• 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: autorelease use...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autorelease use...


  • Subject: Re: autorelease use...
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 18 Jul 2005 10:13:59 -0700


On Jul 18, 2005, at 7:20 AM, Tristan O'Tierney wrote:

for example say you do:
- ( void ) myFunction {
NSString *str = [NSString stringWithString: @"my string"];
}
once you reach the end of myFunction, you are NOT guaranteed that the
contents of str will still exist, as it has been autoreleased and upon the
next iteration of the event loop this object will be released / dealloced.
however, say you want to pay attention to this variable and keep it for
later use, you would then do a retain:
- ( void ) myFunction {
NSString *str = [NSString stringWithString: @"my string"];
[str retain];
}


NO!

This is not right.

Please, there are any number of resources that properly describe Cocoa's memory management model. There is typically very little point in trying to write your own reference in response to a question -- especially if you then get it wrong.

mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >autorelease use... (From: Luc Vandal <email@hidden>)
 >Re: autorelease use... (From: "Tristan O'Tierney" <email@hidden>)

  • Prev by Date: Re: Special Borders
  • Next by Date: Re: NSTextView completion
  • Previous by thread: Re: autorelease use...
  • Next by thread: Re: autorelease use...
  • Index(es):
    • Date
    • Thread