Fat*_*tie 1 iphone cocoa cgcontext cglayer
当您创建这样的CGLayer,然后获取上下文...似乎无法释放CGContextRef?
释放CGLayerRef本身(显然)工作正常.
您认为可以在发布CGLayer之前释放CGContextRef - 但不是吗?在释放CGLayer之后,你也不能释放CGContextRef.
如果您释放CGContextRef,应用程序崩溃.
CGLayerRef aether = CGLayerCreateWithContext(
UIGraphicsGetCurrentContext(), CGSizeMake(1024,768), NULL);
CGContextRef weird = CGLayerGetContext(aether);
// paths, strokes, filling etc
// paths, strokes, filling etc
// try releasing weird here
CGLayerRelease(aether);
// or, try releasing weird here
Run Code Online (Sandbox Code Playgroud)
有谁知道这里发生了什么?(进一步注意,CGContextRelease确实与CFRelease相同,只有一些nil检查.)
实际上你应该永远不要手动释放CGContextRef吗?有人知道吗?干杯.
CGContextRelease(weird); // impossible, not necessary, doesn't work???
Run Code Online (Sandbox Code Playgroud)
关于乔尔的精彩答案如下:
是否正确释放CGLayerRef?Joel指出:
"是的,因为您从中获取它的功能在其签名中有'Create'.请参阅:documentation/CoreFoundation /"
您不拥有从CGLayerGetContext返回的上下文,因此不应该释放它*.特别是,请参阅http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/writerid/cfGetRule,了解有关"获取"功能的信息.核心基金会.
*:至少,您不应该在给定示例代码的情况下发布它.如果你先保留它(CGContextRetain(怪异)),那么你应该有一个CGContextRelease来平衡它.
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |