• 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: Correct memory management in -awakeAfterUsingCoder: ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Correct memory management in -awakeAfterUsingCoder: ?


  • Subject: Re: Correct memory management in -awakeAfterUsingCoder: ?
  • From: Michael Ash <email@hidden>
  • Date: Tue, 5 May 2009 11:13:22 -0400

On Tue, May 5, 2009 at 12:45 AM, Graham Cox <email@hidden> wrote:
> If I retain the object before returning it in -awakeAfterUsingCoder:, the
> problem goes away, but this appears to violate normal memory management
> rules, so it's not clear that this is the correct solution. The
> documentation doesn't explicitly say anything about this either.

Actually it fits them just fine, when you look at the rules like this:

- Within any pair of {}, the number of calls to alloc, copy, and
retain must match the number of calls to release and autorelease.

Generally there's an exception for init/dealloc methods, but if you
use accessor religiously then you don't even need that exception.
Following this rule (which is not from Apple's docs, but comes from
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html), you
balance the release with a retain (or alloc or copy).

Mike
_______________________________________________

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: 
 >Correct memory management in -awakeAfterUsingCoder: ? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Bindings related NSUndoManager problem
  • Next by Date: Re: WTF? Is a file corrupted?
  • Previous by thread: Re: Correct memory management in -awakeAfterUsingCoder: ?
  • Next by thread: Re: Registering Clients using DO
  • Index(es):
    • Date
    • Thread