Note that there are some explanatory texts on larger screens.

plurals
  1. PONSOutlineView/NSTreeController not releasing all model objects after removing them
    primarykey
    data
    text
    <p>I have a very basic app: a window with an <code>NSOutlineView</code> bound to an <code>NSTreeController</code>. The outline view displays a simple model object (<code>TCCard</code>). I added two buttons so that I can add and remove model objects from the outline view.</p> <p>Looking at the app in Instruments (Leaks) I can see that new instances of my model object are created when I add them, but not all are released when I delete them from the outline view. Two or three instances of my model object always remain "living" even when the outline view has no more entries.</p> <p>Is the outline view or tree controller doing some caching behind the scenes? Code below:</p> <pre><code>#import "TCAppDelegate.h" #import "TCCard.h" @implementation TCAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { TCCard *first = [TCCard new]; first.title = @"First card"; // tree controller content is bound to self.cards: self.cards = [@[first] mutableCopy]; } - (IBAction)addCard:(id)sender; { TCCard *second = [TCCard new]; second.title = [NSString stringWithFormat:@"%ld card", self.cards.count]; [self.treeController addObject:second]; } - (IBAction)deleteCard:(id)sender; { NSIndexPath *path = [NSIndexPath indexPathWithIndex:self.cards.count - 1]; [self.treeController setSelectionIndexPath:nil]; [self.treeController removeObjectAtArrangedObjectIndexPath:path]; // some model objects continue to live } @end </code></pre> <p>This is a very basic example. In my real app those model objects are quite "heavy" with a lot of references to other objects. I really would like all of them to be released when they are removed from the view.</p> <p><strong>EDIT</strong>: This problem can be reproduced even with Apple's sample code: <a href="https://developer.apple.com/library/mac/#samplecode/DragNDropOutlineView/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008831" rel="nofollow">https://developer.apple.com/library/mac/#samplecode/DragNDropOutlineView/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008831</a></p> <p>Run in the example in Instruments and search for <code>SimpleNodeData</code>. Watch the number of instances and then delete all nodes from the example app (via the context menu).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload