• 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
Re: NSOutlineView Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView Problem


  • Subject: Re: NSOutlineView Problem
  • From: John Terranova <email@hidden>
  • Date: Wed, 9 Jun 2004 22:29:53 -0700

On Jun 9, 2004, at 9:01 PM, Scott Ahten wrote:

On Jun 9, 2004, at 4:44 PM, Andreas Mayer wrote:

Am 09.06.2004 um 21:08 schrieb Scott Ahten:

When is it safe to release the objects returned to an NSOutlineView in outlineView:child:ofItem?

When you don't need the outline view anymore?

If it was only that simple :)

My data source asks the item (XMLTree http://iharder.net/macosx/xmltree/ ) for it's child at the requested index and returns it. The object is created by the item and I pass it on to the outline view when requested.

// Simplified version of the method...
- (id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item
{
XMLTree * childTree;
// is the parent non-nil?
if (item) {
childTree = [item childAtIndex:index];
} else {
// Else return the root
childTree = [docTree childAtIndex:1];
}
return [childTree retain];
}

Looking at the source for childAtIndex, the item creates a new XMLTree based on the child node (a CFXMLTreeRef) and returns it autoreleased. Since the outline view calls this method multiple times for the same child, multiple versions of same child are created.

This is your problem. You should already have created your objects (XMLTree, CFXMLTreeRef, whatever) and you need to maintain these objects in some data structure (e.g. array, tree, dictionary) yourself. Then in - (id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item you just return your copy of the object.

Since you are returning an object you already own, the object should not be going away anytime soon. The outlineview will neither retain nor [auto]release the object as it is not going to hold onto the object long enough to bother, rather it will just ask for the object again every time it needs it. This is why your outlineview:child:ofItem: routine must be fast (it should not be creating objects every time), just accessing a data structure to grab an existing object and return it.

Just as the outlineview neither retains nor [auto]releases the object, you shouldn't either when you return the object to the outlineview.

It might make sense (depending on your data) to create the data lazily. The first time the outlineview asks you for it, you create it and return it. But, you also store the object in your own data structures, so that the next time the outlineview asks for the object, you don't have to create it, you just get it from your data structure.
--
john terranova, email@hidden

"You never know what you'll do
until you do what you do
when you're broke." -- Todd Snider, "Broke"
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSOutlineView Problem
      • From: Scott Ahten <email@hidden>
    • Re: NSOutlineView Problem
      • From: Andreas Mayer <email@hidden>
References: 
 >NSOutlineView Problem (From: Scott Ahten <email@hidden>)
 >Re: NSOutlineView Problem (From: Andreas Mayer <email@hidden>)
 >Re: NSOutlineView Problem (From: Scott Ahten <email@hidden>)

  • Prev by Date: Re: Word count
  • Next by Date: Re: two things (newbie)
  • Previous by thread: Re: NSOutlineView Problem
  • Next by thread: Re: NSOutlineView Problem
  • Index(es):
    • Date
    • Thread