Re: controllers, delegates, retain, release ...
Re: controllers, delegates, retain, release ...
- Subject: Re: controllers, delegates, retain, release ...
- From: Quincey Morris <email@hidden>
- Date: Fri, 22 Feb 2008 12:10:35 -0800
On Feb 22, 2008, at 10:39, Jack Repenning wrote:
In the current structure, Controller performs
{
UI *ui = [[UI alloc] initWithContext: context];
[ui run: @selector(doSomething) title: @"Title"];
}
That is: the UI object is alloc'ed (creating a release obligation),
but is not (auto)released here, nor is any reference to it saved
anywhere so it may be (auto)released later. Controller has nothing
to do with releasing this object, which is the bit that sticks in my
craw.
Rather, over in UI we have:
-(void)windowWillClose:(NSNotification *)aNotification
{
[self autorelease];
}
FWIW, I wouldn't call it wrong for an object to manage its own
lifetime. You'll leak UIs if the notification never appears, but this
is apparently not a problem.
You could clarify the code a little bit perhaps by removing the
appearance of leaking from Controller:
{
UI *ui = [[[UI alloc] initWithContext: context] autorelease];
[ui run: @selector(doSomething) title: @"Title"];
}
and putting full control of retention into UI:
-(id) initWithContext: ...
{
...
return [self retain];
}
-(void)windowWillClose:(NSNotification *)aNotification
{
[self autorelease];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden