【发布时间】:2011-08-26 03:01:18
【问题描述】:
这里有问题。我正在创建一个MAAttachedWindow,然后在某个事件发生时将其隐藏。代码如下所示:
-(void)toggleDetailShouldShow:(BOOL)show {
if (show) {
if (!attachedWindow) {
NSPoint buttonPoint = NSMakePoint(NSMidX([[someView someImageView] frame]),
NSMidY([[someView someImageView] frame]));
attachedWindow = [[MAAttachedWindow alloc] initWithView:view
attachedToPoint:buttonPoint
inWindow:window
onSide:12
atDistance:65.0];
//setup here
[attachedWindow setAlphaValue:0.0];
[[[someView someImageView] window] addChildWindow:attachedWindow ordered:NSWindowAbove];
[[attachedWindow animator] setAlphaValue:1.0];
}
}
else {
if (attachedWindow) {
[[[someView someImageView] window] removeChildWindow:attachedWindow];
[attachedWindow orderOut:self];
[attachedWindow release];
attachedWindow = nil;
}
}
}
当这被多次触发时,我的内存使用量稳步攀升。这有什么泄漏的原因吗?
【问题讨论】:
-
具体泄露了什么? MAAttachedWindow?
-
嗯,这就是我的猜测。 Instruments 根本没有显示泄漏,这就是我遇到障碍的地方。这是我在内存不断增加时触发的唯一代码。这就是为什么我认为是这个窗口泄漏了。
-
只是半相关的,但我可以建议我的 SFBPopoverWindow 类 - github.com/sbooth/SFBPopovers - 它类似于 MAAttachedWindow 但功能略有不同
-
@sbooth:我几乎考虑过使用您的代码,但不幸的是,与 MAAttachedWindow 相比,屏幕边缘的检测相当不稳定。老实说,即使设置为自动,它也会以错误的方式弹出。
-
@sbooth:其实我刚才又看了一遍,配置错了。切换到您的代码,我没有回头。感谢您分享精彩的课程!
标签: objective-c cocoa memory-leaks