Re: question about retain/release
Re: question about retain/release
- Subject: Re: question about retain/release
- From: "Angela Brett" <email@hidden>
- Date: Tue, 23 Dec 2003 12:27:42 +1300 (NZDT)
>
> - (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 ?
newTitle is retained and not released because you want to keep it around,
as an instance variable. It will be released (by the [title release];
line) the next time somebody calls setTitle, or, if setTitle: is not
called again, it should be released in your -dealloc method.
Angela Brett
email@hidden
http://macintosh.geek.nz
_______________________________________________
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.