工作表完成时自动释放处理程序将Xcode分析器标记为过度释放

时间:2016-11-21 05:34:14

标签: xcode cocoa analyzer

所有这些都是非ARC。

在我的DocumentWindowController中,我调用:

-(IBAction)showConfigSheet:(id)sender
{
    [[ConfigSheetController alloc] initWithDocument:[self document]];
}

然后在我的ConfigSheetController类中,我有:

-(id)initWithDocument:(Document *)inDocument
{
    if (self = [super initWithWindowNibName:kConfigSheetNibName])
    {
        [self setDocument:inDocument];
        [[self window] orderOut:self];

        //  run the sheet       
        [[[self document] windowForSheet] beginSheet:[self window] completionHandler:^(NSModalResponse returnCode)
        {
            if (returnCode == NSModalResponseOK)
            {
                ... do stuff ...
            }

            else if (returnCode == NSModalResponseCancel)
            {
                ... do different stuff ...
            }

            //  we need to rebuild from the nib each time so release ourselves
            //  because we were alloc'd in the DocumentWindowController and
            //  this will release us after OK or Cancel is clicked

            [self autorelease];  
        }];
    }

    return (self);
}

对于[自我自动释放],Xcode分析器说"对象自动释放太多次"。为什么?工作表在块内发生,一旦完成,它将在返回时释放工作表。

此代码可以正常工作,控制台中没有崩溃或错误。

0 个答案:

没有答案