Re: Outline View not retaining objects it uses. Why?
Re: Outline View not retaining objects it uses. Why?
- Subject: Re: Outline View not retaining objects it uses. Why?
- From: Aaron Burghardt <email@hidden>
- Date: Sat, 19 Jul 2008 22:53:48 -0400
On Jul 19, 2008, at 8:56 PM, Paul Sargent wrote:
On 19 Jul 2008, at 22:49, Andy Lee wrote:
On Jul 19, 2008, at 5:35 PM, Paul Sargent wrote:
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.
Maybe this is relevant:
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/ObjectOwnership.html#//apple_ref/doc/uid/20000043
>
In Cocoa, references to table data sources, outline view items,
notification observers, and delegates are all considered weak (for
example, an NSTableView object does not retain its data source and
the NSApplication object does not retain its delegate).
Thank for the pointer Andy.
I can see why all the other items are on that list, but why outline
view items? ... and by extension should table view items be on that
list too?
As the delegate, it is your responsibility to tell the outline view or
the table view when your data model changes by sending it -
reloadData. However, since you created a dictionary on the fly and
did not cache it yourself, your data model effectively changed as soon
as you returned. Thus, you really should have called reloadData right
away, which would cause a vicious infinite loop (because you would
create a new un-cached dictionary, which would require another call to
reloadData, ...).
In other words, you were thinking about it in terms of retain counts,
but conceptually you were expecting the view to manage part of your
data model (by expecting it to cache your temporary items). If a
temporary item is needed for performance reasons, your model must take
care of it. If you are familiar with Core Data, that's exactly what a
fault object is: a place-holder until the actual data is needed.
Here's an exercise for the reader: if you decide create some cached,
temporary objects, do you call reloadData every time the cache is
updated?
BTW, was that your actual code? If so, this is a bug:
return [NSDictionary dictionaryWithObjectsAndKeys:aDataItem,
@"DataItem", extraInfo, @"ExtraInfo"];
should be:
return [NSDictionary dictionaryWithObjectsAndKeys:aDataItem,
@"DataItem", extraInfo, @"ExtraInfo", nil];
Aaron
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden