Re: get ref to instance from IB
Re: get ref to instance from IB
- Subject: Re: get ref to instance from IB
- From: Ken Thomases <email@hidden>
- Date: Tue, 16 Jun 2009 01:00:13 -0500
On Jun 15, 2009, at 11:28 PM, Graham Cox wrote:
On 16/06/2009, at 1:55 PM, Paul M wrote:
Also: do I need to track and clean up all these wrapper instanes?
I'm assuming I dont - I hope I dont otherwise it'll be a complete
nightmare.
You need to follow normal, standard memory management and object
ownership rules. That doesn't necessarily involve "tracking" all the
wrapper instances, but it doesn't let you off following the rules
correctly. In this case, autoreleasing the objects when they are
created is probably all you need to do (and +[NSValue
valueWihtPointer:] does this anyway).
Actually, I believe a data source has stricter requirements on it than
merely following the memory management rules.
From <http://developer.apple.com/documentation/Cocoa/Conceptual/OutlineView/Articles/UsingOutlineDataSource.html#//apple_ref/doc/uid/20000725-140686
>:
"Similarly, [the outline view] does not own the objects it gets from
the data source—if they are released your application is likely to
crash unless you tell the outline view to reload its data. ... The
data source is ... responsible for retaining all of the objects it
provides to an outline view, and updating the outline view when
there’s a change to the model. It is therefore not safe to release
the root item—or any children—until you’re no longer displaying
it in the outline view. If you need to dispose of the root item, then
you should ensure that references to it are nullified, and that the
outline view is updated to ensure that no attempt is made to display
other items that may also have been disposed of ... ."
Also, note the following from the description of -
outlineView:child:ofItem:
"In order for the collapsed state of the outline view to remain
consistent when it is reloaded you must always return the same object
for a specified child and item. "
And similarly, from the description of -
outlineView:objectValueForTableColumn:byItem:
"In order for the collapsed state of the outline view to remain
consistent when it is reloaded you must always return the same object
for the specified item."
I think there's no getting away from the need for the data source to
maintain all of the objects it vends. It can allocate them lazily, on
demand. The object can be owned by the C++ object, or there can be a
mapping from each C++ object to the corresponding Objective-C object,
or you can maintain an Objective-C data structure that parallels the C+
+ data structure.
Regards,
Ken
_______________________________________________
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