Re: NSString's "mutableCopy" creating a leak?
Re: NSString's "mutableCopy" creating a leak?
- Subject: Re: NSString's "mutableCopy" creating a leak?
- From: Andy Lee <email@hidden>
- Date: Wed, 1 Oct 2008 16:45:58 -0400
On Oct 1, 2008, at 4:16 PM, Christopher J Kemsley wrote:
I was not aware that I shouldn't explicitly call a dealloc...
The documentation for -dealloc says so in so many words.
Why not? Replacing it with a "release" in the object made that leak
go away, but I still don't understand why I can't dealloc it.
-dealloc frees the memory that was allocated for the object. That
memory should only be freed when nobody else is using the object. But
in general you can't assume you know when nobody else is using the
object. You might add some code tomorrow that does some additional
retains on the object. You might pass the object to some Cocoa class
or third-party class that retains the object unbeknownst to you.
There may be some non-deterministic code path that sometimes retains
the object and sometimes doesn't.
So you don't try to know when to free the object's memory. Instead,
you balance your retains and releases and let the runtime take care of
it. The runtime will call -dealloc when the object's retain count
goes to zero -- whenever that may be.
--Andy
_______________________________________________
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