Re: autorelease use...
Re: autorelease use...
- Subject: Re: autorelease use...
- From: "Tristan O'Tierney" <email@hidden>
- Date: Mon, 18 Jul 2005 10:20:02 -0400
autorelease is a handy way to return a value, and guarantee that it will be
freed even if the context in which it's returning do does not itself call an
explicit [object release].
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];
}
at this point the object will stick around past the length of this function
(guaranteed). think of autorelease as "release later" or, "let my parent
callee determine if i should be retained, not myself." this removes the
confusion out of "who should manage memory with helper functions. the caller
or callee?"
On 7/18/05, Luc Vandal <email@hidden> wrote:
>
> Hi!
>
> when should I use autorelease? Should I use it every time I use for
> example init.. or stringWithString?
>
> Luc
>
> _______________________________________________
> 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
>
--
Tristan O'Tierney
- Email: tristan [TA] otierney <DOT> net
- Homepage: http://www.otierney.net
_______________________________________________
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