Problem reloading data for NSOutlineViewDataSource without memory leak
Problem reloading data for NSOutlineViewDataSource without memory leak
- Subject: Problem reloading data for NSOutlineViewDataSource without memory leak
- From: "Alexander F. Hartner" <email@hidden>
- Date: Thu, 20 Jan 2005 07:24:16 +0200
Within my implementation of NSOutlineViewDataSource I am reloading it's data which is stored in an array (NSArray). When the data changes I am trying to replace the current array with a new array and dispose of the old array as show below:
- (void)refreshContact
{
NSArray * oldContacts = nil;
//Check if current contacts exist and copy reference to current contact
if (contacts != nil)
{
oldContacts = contacts;
}
//construct new array and assign to current reference
contacts = ... //Construct new array here
[contacts retain];
//release old array
if (oldContacts != nil)
{
[oldContacts release];
}
[contactsView reloadData];
}
I got this technique from Memory Management 101 (www.cocoadevcentral.com). The problem I get occurs once the NSOutlineView reload it's data during the reloading (
[contactsView reloadData]). It seems that the NSOutlineView maintains a reference to the items provided by the data source beyond the call to reload data. The result is a application crash with the error :
...has exited due to signal 11 (SIGSEGV).
As soon I comment out the line
oldContact release the application behaviour is correct and the view reloads the correct data. Everything is working correctly except the fact that the previous / old items are never released and deallocated.
How can I replace my current array of items with a new array in a clean way ?
Thanks
Alex
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden