Re: NSOutlineView: expanding an item retains it?
Re: NSOutlineView: expanding an item retains it?
- Subject: Re: NSOutlineView: expanding an item retains it?
- From: Charlton Wilbur <email@hidden>
- Date: Mon, 24 Jan 2005 06:51:27 -0500
On Jan 24, 2005, at 6:08 AM, j o a r wrote:
But back to the topic of this thread: Why should an NSOutlineView
retain an item provided by the data source? The data source must in my
opinion be responsible for retaining all objects that it contains for
as long as they are valid (ie. until reloadData are next called). So
what would be the point of having the outline view also retaining
them? To be able to use them after reloadData is called? Doesn't make
much sense, right?
Imagine a multithreaded situation. Thread 1 handles the model, perhaps
interacting with other computers. Thread 2 responds to user actions.
It's entirely possible for Thread 1 to release an object, then for
Thread 2 to do something with the outline View -- perhaps expanding the
object that was just released -- then for Thread 1 to send the
reloadData message.
What does it gain you if the outline view retains the items provided to
it? You don't crash in that situation, or in similar ones where
reloadData might not be called immediately. What does it cost you?
Provided that both the outline view and your code are retain/release
balanced, very little. I would expect that the NSOutlineView would
release all items provided to it upon receipt of a reloadData message,
for that matter; the point is to ensure that the objects do not vanish
out from underneath it, to allow for graceful event handling in the
event of a programmer not calling reloadData in a timely manner after
releasing an object.
More importantly, it doesn't really matter if NSOutlineView retains the
objects handed to it or not, so long as it behaves as it is documented.
In the case of collection classes, by contrast, it's important to know
that collections retain objects stored in them, and knowing that makes
memory management easier. In the case of an NSOutlineView, it doesn't
really matter, so long as Apple's code is retain/release balanced.
Charlton
--
Charlton Wilbur
email@hidden
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden