On Jul 19, 2008, at 14:35, Paul Sargent wrote:

I've got an outline view that has a data source. The data source has routines that look like this:

-(id) outlineView:(NSOutlineView *) aView child:(NSInteger) anIndex ofItem:(id) anItem {
        id aDataItem = [someArray objectAtIndex:anIndex];
return [NSDictionary dictionaryWithObjectsAndKeys:aDataItem, @"DataItem", extraInfo, @"ExtraInfo"];
}

-(id) outlineView:(NSOutlineView *) aView objectValueForTableColumn: (NSTableColumn *) aColumn byItem:(id) anItem {
        id dataItem  = [anItem objectForKey:@"DataItem"];
        id extraInfo = [anItem objectForKey:@"ExtraInfo"];

        .....
}

This works fine the first time the view is populated, but when it's refreshed it just calls the second method with the pointers to the dictionaries I return first time round. Trouble is they've been autoreleased by now.

I think you mean "deallocated", not "autoreleased". The question is, what's your evidence that they're deallocated? Is something crashing?

The main thing that's wrong here is that you're returning a *different* object from outlineView:child:ofItem: each time. You should return the same object if you are given the same parameters. If finding extraInfo is not incredibly expensive, you could just return aDataItem in the first method, and find extraInfo in the second.

(Of course, you would return a different object if the data actually changed, but the middle of a refresh cycle is probably not a good time for that to happen.)

I know how to fix this, but I'm looking to understand.

Why, if the outline view is holding pointers to the objects I return from "outlineView:child:ofItem:", doesn't it retain them?
Why was I wrong to assume that an autoreleased object was sufficient?
Would the pointers it holds be strong or weak in a GC program?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to