I have a variable declared like this:
@property (nonatomic, retain) NSMutableArray *aInfo;
At the beggining, if I declare the variable like this:
self.aInfo = [[NSMutableArray alloc] init];
In every point of the app, I can stop the execution with a break point and print the variable content like this:
po self.aInfo
BUT, if I declared the variable with autorelease (as it should be), I cannot see the content anymore in my breakpoint…
self.aInfo = [[[NSMutableArray alloc] init] autorelease];
PD: If I do something like NSLog(@”%@”, self.aInfo) I can see the content…
As it shouldn’t be. Try this:
Or use a convenience method, which is in the autorelease pool and which you do not own, so it can be assigned directly:
or:
Remember that when you set up your property to “retain,” it does just that. Its synthesized accessors will release the old assignment and retain the new one. So if you assign an alloc’d instance to it directly, that instance will be retained twice, creating a memory leak.*
*Edit: See deanWombourne’s comments below.
alloc] init] autoreleaseas a direct assignment to a retained property will not create a memory leak. But I remain unconvinced that it is memory-efficient.