Reputation: 679
I'm currently learning objective-c and I'm currently training with NSTableView.
Here is my problem :
I have linked my tableview to my controller through Interface Builder so that it has a datasource, I have implemented NSTableViewDataSource protocol in my controller and I have implemented both -(NSInteger) numberOfRowsInTableView:
and -(id) tableView:objectValueForTableColumn:row:
methods.
I have created a raw business class ("person") and I succeeded to display its content into my NSTableView.
But then, I put some NSLog
in my dealloc methods to see whether the memory was freed or not and it seems that my array as well as my "person" instances are never released.
here is my dealloc code in the controller:
-(void)dealloc
{
NSLog(@"the array is about to be deleted. current retain : %d",[personnes retainCount]);
[personnes release];
[super dealloc];
}
and in my "person" class
-(void) dealloc
{
NSLog(@"%@ is about to be deleted. current retain : %d",[self prenom],[self retainCount]);
[self->nom release];
[self->prenom release];
[super dealloc];
}
When these deallocs are supposed to be called in the application lifecycle? Because I expected them to be called at the window closure, but it didn't.
In the hope of beeing clear enough,
Thanks :)
KiTe.
Upvotes: 1
Views: 390
Reputation:
I’m assuming you’re never releasing the window controller object that owns the (only) window. As such, the window controller and every top level object in the nib file are retained throughout the application lifecycle, including the window (and its views).
Since the window controller exists throughout the application lifecycle, it isn’t released, hence its -dealloc
method is never called. And, since the controller -dealloc
method is never called, its personnes
array isn’t released.
The personnes
array owns its elements. Since the array isn’t released, neither are its elements, hence the -dealloc
method of the corresponding class/instances is never called.
Upvotes: 4
Reputation: 49354
Don't ever use retainCount
. The results are misleading at best. If you practice proper memory management practices, you'll be fine. Have you had any memory issues/crashes?
Upvotes: 2