RE: question about retain/release
RE: question about retain/release
- Subject: RE: question about retain/release
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 22 Dec 2003 14:19:05 -0500
>
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 ?
Because you don't want newTitle to be deallocated yet. You want to keep
that object around so you can use it as the object's new title.
Remember, you are dealing with pointers. The code means that if newTitle
does not point to the same object as title (which is also a pointer), then
release the object title points to and retain the object that newTitle
points to. Also, make title point to the object that newTitle points to.
The next time this code is invoked, title is pointing to the object that
used to be pointed to by newTitle. That object is released when a new
object is passed into the method.
Does that help?
Jonathan
_______________________________________________
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.