Non-ARC beginSheetModalForWindow?


#1

If I am not using ARC, exactly when is is safe to release the panel returned from [NSOpenPanel openPanel]?
Or do I even need to? I would think the code below leaks panels, but the analyzer doesn’t complain and a cursory run through Instruments shows it is OK. :open_mouth:

- (IBAction)showOpenPanel:(id)sender
{
    __block NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setAllowedFileTypes:[NSImage imageFileTypes]];
    
    [panel beginSheetModalForWindow:[stretchView window] completionHandler:^ (NSInteger result) {
        if (result == NSOKButton) 
        {
            NSImage *image = [[NSImage alloc] initWithContentsOfURL:[panel URL]];
            [stretchView setImage:image];
            [image release];
        }
    }];
}

I can tell you releasing the panel at the end of the block (under 10.6.8) does not make for happiness.
What gives? Is there some behind-the scenes interactions with __block and autorelease pools?
Thx in advance!