• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem reloading data for NSOutlineViewDataSource without memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Problem reloading data for NSOutlineViewDataSource without memory leak
      • From: Jeremy Dronfield <email@hidden>
  • Prev by Date: Re: Converting sound
  • Next by Date: Re: Cocoa bindings and a custom view...
  • Previous by thread: Re: Cocoa bindings and a custom view...
  • Next by thread: Re: Problem reloading data for NSOutlineViewDataSource without memory leak
  • Index(es):
    • Date
    • Thread