Objective c 我称之为';发布';而不是';关闭';在窗户上?

Objective c 我称之为';发布';而不是';关闭';在窗户上?,objective-c,cocoa,Objective C,Cocoa,完成弹出窗口后,我将调用以下代码行: if (imageDroppedActionPopup) { [[self window] removeChildWindow:imageDroppedActionPopup]; [imageDroppedActionPopup orderOut:nil]; [imageDroppedActionPopup close]; imageDroppedActionPopup = nil; } 我现在想知道我是否可以替换 [ima

完成弹出窗口后,我将调用以下代码行:

if (imageDroppedActionPopup) {
    [[self window] removeChildWindow:imageDroppedActionPopup];
    [imageDroppedActionPopup orderOut:nil];
    [imageDroppedActionPopup close];
    imageDroppedActionPopup = nil;
}
我现在想知道我是否可以替换

[imageDroppedActionPopup close];

它似乎工作正常。但我想知道这是否正确


我这样做的原因是,如果出于某种原因使用close,应用程序焦点将返回到主文档窗口,而不是当前的NSWindowController窗口,它是上述弹出父窗口。

close
将窗口从屏幕上移除,
release
减少对象的retain计数器,可能会导致也可能不会导致它被释放

这似乎是有效的,因为解除分配意味着从屏幕上删除,但这些方法永远无法相互替换。即使您是唯一的所有者,您也永远无法确定
释放
会导致立即解除分配(因此也不会导致窗口立即消失),因为该窗口可能是由其他人临时保留的

需要关闭窗口时,请调用
close
。而且您必须严格按照内存管理规则,仅对保留、分配或复制的对象调用
release


考虑到将
close
替换为
release
不会导致崩溃,我认为您需要两者。

您不需要使用
close
。调用
orderOut:
将关闭窗口。您应该在将其作为子窗口删除之前执行此操作。这将防止您看到的窗口排序问题

只要这样做:

if (imageDroppedActionPopup) 
{
    [imageDroppedActionPopup orderOut:nil];
    [[self window] removeChildWindow:imageDroppedActionPopup];
    [imageDroppedActionPopup release];
    imageDroppedActionPopup = nil;
}

请注意,在将其设置为
nil

确定之前,我仍然在窗口上调用
release
。您知道为什么关闭弹出窗口会导致当前窗口移回主文档窗口的后面吗?你可以在问题中看到我的代码。。。
if (imageDroppedActionPopup) 
{
    [imageDroppedActionPopup orderOut:nil];
    [[self window] removeChildWindow:imageDroppedActionPopup];
    [imageDroppedActionPopup release];
    imageDroppedActionPopup = nil;
}