gpt4 book ai didi

objective-c - 如何阻止 NSImage lockfocus 在 NSOperation 中泄漏内存?

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:45 25 4
gpt4 key购买 nike

当我使用锁定/解锁焦点向 NSImages 绘制时,我遇到了内存泄漏问题。当我注释掉下面的 LEAKS HERE 代码时,泄漏就消失了。所以我知道这就是泄漏发生的地方。

for(int i= 0; i < nNumberImages; ++i)
{
m_apNSImageArray[i]= [[NSImage alloc] initWithSize:m_viewRect.size];
if(!m_apNSImageArray[i])
{
return;
}

//LEAKS IN THIS CODE HERE
[m_apNSImageArray[i] lockFocus];

//EDIT: Commented the lines below out, but leak persists.
//[[[[NSApp delegate] getColors] getAudioWaveColor:YES] setStroke];
//[[m_pmaBezierPaths objectAtIndex:i] stroke];

[m_apNSImageArray[i] unlockFocus];
//TO HERE
}

我正在使用垃圾回收,这个 for 循环是在 OSX 10.7 Lion 的 NSOperationQueue 中运行的 NSOperation 的一部分。

这是 NSImage 对后台线程/操作的锁定焦点的错误吗?

编辑:看起来 lockFocus 每次调用时都在分配新空间。

最佳答案

我有一个几乎相同的问题,需要添加一个自动释放池。

非 ARC:

// set up the autorelease pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// do image stuff
NSImage *imagemage = [[NSImage alloc] init];
[maskedImage lockFocus];
[maskedImage unlockFocus];
[image release];

// drain the autorelease pool
[pool drain];

圆弧:

@autoreleasepool {
NSImage *imagemage = [[NSImage alloc] init];
[maskedImage lockFocus];
[maskedImage unlockFocus];
}

关于objective-c - 如何阻止 NSImage lockfocus 在 NSOperation 中泄漏内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7099722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com