Re: autorelease use...
Re: autorelease use...
- Subject: Re: autorelease use...
- From: John Stiles <email@hidden>
- Date: Mon, 18 Jul 2005 11:33:38 -0700
Still, "arbitrary examples" like this are less useful than just
pointing to the docs. Particularly when, as written, your example
just leak a string (since you're not saving it in any way so it can
be released later).
Apple's docs are ultra clear about memory management, so just point
newbies to the docs.
On Jul 18, 2005, at 11:28 AM, Tristan O'Tierney wrote:
i think you misunderstood the point of my example. the point was,
if you
wanted the string to stick around PAST THE LENGTH of the function,
you need
to retain it. it was just an arbitrary example, without me having
to dive
into member variables, object dealloc methods that properly release
the
variable, etc, etc, etc.
On 7/18/05, Charilaos Skiadas <email@hidden> wrote:
On Jul 18, 2005, at 9:20 AM, Tristan O'Tierney wrote:
- ( void ) myFunction {
NSString *str = [NSString stringWithString: @"my string"];
[str retain];
}
Unless I'm mistaken, this will leak, no? str is a local variable
declared
in the function, so it is lost the moment you exit the function,
and the
retained object sticks around forever. I am guessing what you
meant was the
same without NSString * in front, where it is assumed that str is an
instance variable of the object in question?Or have I gotten it
all wrong?
To Luc: Joar's email really nailed the issue. You should think of
memory
management in terms of ownership. Should your object own the other
object or
not?
Haris
--
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:
40blizzard.com
This email sent to email@hidden
_______________________________________________
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