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 08:20:33 -0500
On Jan 24, 2005, at 7:44 AM, j o a r wrote:
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.
You have to be kidding? Is that how you usually ensure thread
"safety"? :-D
No, I'm not kidding. It's a belt-and-suspenders approach. What it
eliminates is difficult-to-track down bugs.
I imagine it's a better use of Apple engineers' time to match retains
and releases in NSOutlineView than it is to handle all the bug reports
filed in error because they chose to make their design aesthetically
pure rather than resilient.
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.
If you crash because the controller doesn't call reloadData when it
should, then that's a bug in the controller, and not something for the
data source or outline view to be concerned with.
Yes, and it can be a very difficult to track down bug, and thus while
it might not be something for the outline view to be concerned with, it
*is* something for the authors of the outline view code to be concerned
with.
Not long ago I spent over two weeks tracking down *one* bug, which in
the end turned out to be a release applied too early.
What does it gain you if NSOutlineView retains objects handed to it?
It eliminates a class of bugs that would otherwise be difficult to
track down and in all likelihood blamed on Apple, and turns them into
obvious and easy-to-track down bugs. What does it cost you? Very
little. That seems to me to be a worthwhile tradeoff.
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