当您像这样创建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
有谁知道这里发生了什么?(进一步注意,CGContextRelease 确实与 CFRelease 相同,但有一些 nil 检查。)
事实上,你不应该手动释放 CGContextRef 吗?有人知道吗?干杯。
CGContextRelease(weird); // impossible, not necessary, doesn't work???
关于乔尔的精彩回答如下:
释放CGLayerRef是否正确和正确?Joel 指出:
“是的,因为您从中获取它的函数的签名中包含‘Create’。请参阅:documentation/CoreFoundation/”