• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString's "mutableCopy" creating a leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: NSString's "mutableCopy" creating a leak? (From: Christopher J Kemsley <email@hidden>)

  • Prev by Date: Re: Finding other apps' paths - deterministically!
  • Next by Date: Re: NSString's "mutableCopy" creating a leak?
  • Previous by thread: Re: NSString's "mutableCopy" creating a leak?
  • Next by thread: Re: Finding other apps' paths - deterministically!
  • Index(es):
    • Date
    • Thread