当您创建像这样的CGLayer,然后得到context...it似乎不可能发布CGContextRef
发布CGLayerRef本身(显然)很好。
你会认为你可以在发布CGContextRef之前发布CGLayer --但不是吗?您也不能在发布CGContextRef之后发布CGLayer。
如果你发布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有人知道这是怎么回事吗?(请进一步注意,CGContextRelease实际上与CFRelease完全相同,需要进行一些零检查。)
实际上,您不应该手动发布CGContextRef吗?有人知道吗?干杯。
CGContextRelease(weird); // impossible, not necessary, doesn't work???关于Joel惊人的回答如下:
发布CGLayerRef正确吗?乔尔指出:
“是的,因为您从其中获得的函数在其签名中已经‘创建’了。参见: documentation/CoreFoundation/”
发布于 2011-01-04 12:56:40
您不拥有从CGLayerGetContext返回的上下文,因此不应该释放它*。特别是,有关核心基础中的“Get”函数的信息,请参见http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/writerid/cfGetRule。
*:至少,考虑到示例代码,您不应该发布它。如果您先保留它(CGContextRetain(怪异)),那么您应该有一个CGContextRelease来平衡它。
https://stackoverflow.com/questions/4593709
复制相似问题