Re: NSMutableString question
Re: NSMutableString question
- Subject: Re: NSMutableString question
- From: Graham Cox <email@hidden>
- Date: Wed, 17 Sep 2008 12:50:14 +1000
On 17 Sep 2008, at 12:41 pm, Roland King wrote:
Is that actually guaranteed to release the string *right now*? I
only ask because I seem to recall a message a couple of months ago
about a more complicated object where it appeared that the
initializer did a retain/autorelease on the object so it ended up in
the autorelease pool before you even got hold of it. That was not an
object obtained from a convenience method either IIRC, it was a
[ [ SomeClass alloc ] initConstructorOfSomeSort ] call.
Unlikely the case with NSMutableString I'd think, but perhaps for
other things.
When you call -release, yes, the object is guaranteed to be *released*
right now, because that's what you asked it to do. But releasing is
not deallocating.
The question you have to ask yourself is "why do I absolutely *need*
the object to be deallocated right now?". Cocoa's memory management is
really built around the idea that you don't need to do this, since you
never dealloc an object directly, but instead release it, which is NOT
the same thing.
Generally, init/alloc returns an object that you own, therefore you
should release it. But this says nothing about what else might be
retaining it, such as an autorelease pool. You don't need to know, and
you can't know, whether this is the case, so there's no way to
guarantee an object is ever deallocated at any particular time.
So the question is: why do you think you do need to know?
cheers, Graham
_______________________________________________
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