• 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: Proper retain/release etiquette
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper retain/release etiquette


  • Subject: Re: Proper retain/release etiquette
  • From: Steve Bird <email@hidden>
  • Date: Tue, 23 Jul 2002 11:32:19 -0400

On Tuesday, July 23, 2002, at 11:09 AM, Roarke Lynch wrote:

On Tuesday, July 23, 2002, at 03:42 AM, Ondra Cada wrote

Well, since it is a very very common bug, I would explicitly add that the pattern

// *WRONG*
id foo=[[Xyz alloc] init];
// other code here
[foo release];

is bound to leak as soon as the "other code" happens to raise. Therefore,
the proper pattern is

// *RIGHT*
id foo=[[[Xyz alloc] init] autorelease]; // or just [Xyz xyz], if available
// other code here

or, if you have very hard reasons not to autorelease, you need to use NS_DURING/NS_HANDLER/NS_ENDHANDLER.

What would make this leak? I was under the impression that autorelease was basically a delayed release call.

--- Read it again. The WRONG code has no autorelease. If the "other code"
raises an exception, the [foo release] won't execute. In the RIGHT code,
it won't matter, since it will be released soon anyway.


----------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com (toll free) 1-877-676-8175
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Proper retain/release etiquette (From: Roarke Lynch <email@hidden>)

  • Prev by Date: Re: Proper retain/release etiquette
  • Next by Date: Text Color in custom NSFormatter
  • Previous by thread: Re: Proper retain/release etiquette
  • Next by thread: Re: Proper retain/release etiquette
  • Index(es):
    • Date
    • Thread