Re: Should objects returned by indirection be autoreleased
Re: Should objects returned by indirection be autoreleased
- Subject: Re: Should objects returned by indirection be autoreleased
- From: Eric <email@hidden>
- Date: Sat, 13 May 2006 12:57:49 -0700
I think there's really two questions here, one is whether NSCell will retain
representedObject for itself (throughout its lifetime), and the other is
whether NSCell weill retain representedObject for me. The answer is yes for
the former, and no for the latter.
I believe my original question is about the former rather than the latter.
And Bill correctly points out that I can assume NSCell would retain
representedObject throughout its lifetime for its own use -- in the same
fashion that NSArray retains its objects -- in order to be able to return it
later. Furthermore, since my subclass of NSCell doesn't modify the
retain/release behavior of representedObject of its superclass (NSCell), it
can also assume representedObject will be retained and released
appropriately for itself, to ensure it's allocated while it's alive and
deallocated when it dies. (Since after all, my NSCell subclass is looking
at things from NSCell's perspective, since it is also a NSCell)
I don't think I have any confusion regarding the latter question. Namely,
if I get an object from NSCell (other than it's alloc, copy...etc. methods),
I know NSCell is not going to retain it for me but only for itself, so I'm
going to retain it if I'm going to use it beyond this event loop (or
scope). Otherwise, NSCell would release it under my feet when it dies
while I'm still using it.
-------------------------------------------------------------
Now comes another question that Bill brought up, of whether it's appropriate
to use representedObject for my purpose. What I have is a NSCell that
represents a bookmark button. I'm using the representedObject to refer to
the actual bookmark model object it represent. Does this warrant the use of
representedObject?
Thanks again,
Eric
_______________________________________________
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