• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: controllers, delegates, retain, release ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: controllers, delegates, retain, release ...
      • From: Keith Duncan <email@hidden>
References: 
 >controllers, delegates, retain, release ... (From: Jack Repenning <email@hidden>)

  • Prev by Date: Re: Unobserved Changes
  • Next by Date: Re: -outlineView:heightOfRowByItem: gets an item of NULL??
  • Previous by thread: controllers, delegates, retain, release ...
  • Next by thread: Re: controllers, delegates, retain, release ...
  • Index(es):
    • Date
    • Thread