Re: question about retain/release
Re: question about retain/release
- Subject: Re: question about retain/release
- From: Sven Hoffmann <email@hidden>
- Date: Mon, 22 Dec 2003 22:43:42 +0200
hi thierry,
why would you want to release the value you have just set in the same
method?
a setter method is usually used to set an instance variable of an
object.
a setter retains the newly set value so it will remain availabe for the
object until it
no longer needs it.
once your object does not need the object title is pointing to anymore,
it should send title a release message.
but that is most likely not in the setter method,
which is meant to set instance variables, not release them.
i just started cocoa a few weeks ago and i also struggled with the
memory thing...
keep going!
sven
On Monday, December 22, 2003, at 07:46 PM, Thierry Bucco wrote:
Hi evereybody,
I have a little question.
I am reading some documentations about management
(http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Concepts/ObjectOwnership.html#//apple_ref/doc/uid/20000043/1000580).
There is a setter function like this one :
- (void) setTitle: (NSString*) newTitle
{
if (newTitle != title)
{
[title release];
title = [newtitle retain];
}
}
In several documentation I have read that I have to release every
object I allocate, copy or retain.
So, why newTitle isn't released on this example ?
Thanks.
thierry
_______________________________________________
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.
_______________________________________________
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.