【发布时间】:2012-01-12 13:35:42
【问题描述】:
我最近从使用 NSTimer 切换到 CVDisplayLink 来重绘我的 OpenGL 动画,但在打开 ARC 时我遇到了一点问题:
/*
* This is the renderer output callback function.
*/
static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{
// now is the time to render the scene
[((__bridge BDOpenGLView*)displayLinkContext) setNeedsDisplay:YES];
// always succeeds, because we don't actually do anything here anyway
return kCVReturnSuccess;
}
显示链接回调函数必须用C编写,作为参数使用
// set the renderer output callback function
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
所以我不能在回调中使用self,但是使用((__bridge BDOpenGLView*) displayLinkContext) 会产生内存泄漏:
objc[29390]: Object 0x1001b01f0 of class NSConcreteMapTable autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
我读到,我必须自己设置一个NSAutoreleasePool,但我不能在 ARC 开启的情况下。
我错过了什么吗?
【问题讨论】:
标签: objective-c cocoa core-animation automatic-ref-counting