Re: I think I get most of the memory stuff but...
Re: I think I get most of the memory stuff but...
- Subject: Re: I think I get most of the memory stuff but...
- From: Sherm Pendley <email@hidden>
- Date: Sun, 4 May 2003 22:00:09 -0400
On Sunday, May 4, 2003, at 09:41 PM, Theodore Petrosky wrote:
in a common setter....
-(void)setClientCode:(NSString *) aString {
[aString retain];
[clientCode release];
clientCode=aString;
}
I assume that aString is a convenience construct that
is autoreleased. Why do I have to retain it? Why
doesn't it live through the method?
It *does* live through the method - it'll live until the end of the
current iteration through the event loop, when the autorelease pool
releases it. You need to retain the iVar you're assigning aString to if
you want to access that later, in a future event.
This does precisely the same thing as your original, but it may help
illustrate that you're retaining the iVar to which the incoming
parameter is assigned, not the parameter itself:
-(void)setClientCode:(NSString *) aString {
[clientCode release];
clientCode = aString;
[clientCode retain];
}
sherm--
"I have no special gift, I am only passionately curious." - Albert
Einstein
_______________________________________________
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.