On 26 Jul 2017, at 1:20 pm, Quincey Morris <firstname.lastname@example.org> wrote:
Yes to the release, but not “self”.
OK, this agrees with my own reasoning - I retain the controller prior to the beginSheet, and release it in the completion block. But there’s no other funny business - no NSWindow subclass or anything like that anywhere.
But it is [self release], in this case - which is why it’s kinda bothering me. Maybe some code will help:
- (void) beginModalWithParentWindow:(NSWindow*) parent forGridLayer:(DKOSquareAnnotatedGrid*) gridLayer
self.grid = gridLayer;
self.gridOriginalSettings = gridLayer.settings;
[parent beginSheet:self.window completionHandler:^(NSModalResponse returnCode)
//NSLog(@"ended with %ld", returnCode);
if( returnCode == NSModalResponseCancel )
else if ( returnCode == NSModalResponseOK )
NSUndoManager* um = self.grid.undoManager;
[[um prepareWithInvocationTarget:self.grid] applySettings:self.gridOriginalSettings];
[um setActionName:NSLocalizedString(@"Index Grid Settings", nil)];
So this is my wrapper method in my NSWindowController subclass, that is called by the document. In this case the document doesn’t supply the block, it’s just enclosed inside the wrapper. I’m assuming that it’s the parent window that retains this block until it is invoked.
You can ignore the response stuff - what’s important is that final [self release], which balances the [self retain] at the top of the method.
n.b. I can confirm that the window controller is deallocated after dismissing the sheet, so it would seem all is well - there can’t be a (hidden) retain cycle.
So what’s the problem? Well, the problem is that previously I wasn’t doing this retain/release at all. The window controller was getting autoreleased but everything *appeared* to work just fine, so *something* was apparently retaining the window controller while it was displaying the sheet. I just couldn’t figure out what that could be, which is why I started to wonder about whether anybody was. It’s possible that it was working by chance, and was a crash waiting to happen.