• 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: where does one do the autorelease?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: where does one do the autorelease?


  • Subject: Re: where does one do the autorelease?
  • From: mmalcolm crawford <email@hidden>
  • Date: Thu, 22 Jul 2004 11:40:57 -0700

On Jul 22, 2004, at 11:30 AM, John Spicer wrote:

Where does one put the autorelease in the else clause, before or after
the init? I think after but before I change lots of code I'd like to be
right ;)
- (void) setCOMMENT : (NSString *) str
{
if ([str isKindOfClass:[NSString class]])
{
[COMMENT autorelease];
COMMENT = [str copy];
}
else
{
COMMENT = [[NSString alloc] initWithString:@""];
[COMMENT autorelease];
}
}

Umm, why would you put it after? You're releasing the object you just created (and leaking any previous value of COMMENT)...

<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ Concepts/ObjectOwnership.html>

mmalc
_______________________________________________
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: 
 >where does one do the autorelease? (From: John Spicer <email@hidden>)

  • Prev by Date: Re: forcing a dialog to be the active (front) window
  • Next by Date: Re: Bindings and Buttons
  • Previous by thread: where does one do the autorelease?
  • Next by thread: Re: where does one do the autorelease?
  • Index(es):
    • Date
    • Thread