当您创建一个 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的确与CFREALE相同,并进行了一些零检查。)

实际上,您不应该手动释放CGContexTref吗?有人知道吗?干杯。

CGContextRelease(weird); // impossible, not necessary, doesn't work???

关于乔尔的壮观答案:

正在释放 cglayerref 正确且正确?乔尔指出:
“是的,由于您从签名中获取的功能具有'创建'的功能。请参阅:文档/核心控制/”

有帮助吗?

解决方案

您不拥有从cglayergetContext返回的上下文,因此不应该发布*。特别是,请参阅 http://developer.apple.com/library/mac/#documentation/corefoundation/conceptual/cfmemorymgmgmt/conecteps/ownopher.htmll#/apple/apple_reff/doc/doc/doc/writerid/cfgetrule 有关核心基础中“获取”功能的信息。

*:至少,给定示例代码,您不应将其发布。如果您首先保留它(cgcontextretain(怪异)),则应该有一个cgcontextrelease来平衡它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top