2

I'm somewhat puzzled by object lifetimes under ARC. Here’s a scenario which I think is probably common.

1) In response to some event, was load an NSViewController from a nib.

- (IBAction) doIt: (id) sender
{
     InfoController *editor=[[InfoController alloc]initWithNibName:@"InfoController" bundle:nil];
     [editor show: .... ]
 }

2) The InfoController then displays an NSPopover.

3) Sometime later, the user clicks outside the NSPopover. The popover closes itself.

But when does the InfoController get released? For that matter, what's keeping it alive after doIt returns? In my implementation, InfoController is a data source and delegate for controls in its NSPopover, but in general data sources and delegates aren't retained, right?

Mark Bernstein
  • 2,090
  • 18
  • 23

1 Answers1

4

I realize your question is a bit old now, but I came across it while researching a retain cycle with my NSViewController and NSPopover:

The NSPopover contentViewController property is retaining your NSViewController. That is why you can show the popover like you (and I) do as a response to an action, without another object retaining it. What I found though, is that to properly release the NSViewController under ARC, the contentViewController should be set to nil when the popover is closed. This is in my NSViewController subclass:

- (void)popoverDidClose:(NSNotification *)notification
{
    self.popover.contentViewController = nil;
}
Brian Toth
  • 529
  • 4
  • 14
  • By no means stale; thanks! Do you have a link to the nstruction to releasing the content view? I'd have expected the template method to do this if it were needed. – Mark Bernstein Aug 10 '13 at 03:19