I am confuzed by the memory management of instance members. I have a class with a ivar:
DetailedResultsTableViewController *detailedResultsTableViewController;
and
@property (nonatomic, retain) DetailedResultsTableViewController *detailedResultsTableViewController;
in the .m file:
@synthesize detailedResultsTableViewController;
and
[detailedResultsTableViewController release];
When I initial this variable:
self.detailedResultsMapViewController = [[DetailedResultsMapViewController alloc] initWithNibName:@"DetailedResultsMapViewController" bundle:nil];
I tested the retaincount right after this init and it is 2 !!! if i release it in the end of the function it will fall for not allocated object. What am I doing wrong? how should I initial this type of variable?
Thanks!!
First you should not look at the retaincount, it not really reliable.
Second your property is set to retain. So when you assign some thing to it, it will increase the reatincount. As will
alloc.Doing it like this you are leaking:
you should do:
Or use Autorelease: