gpt4 book ai didi

iphone - 无法释放 CGContextRef(上下文来自 CGLayer)

转载 作者:行者123 更新时间:2023-12-03 16:53:07 24 4
gpt4 key购买 nike

当你像这样创建一个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是否正确且恰当?乔尔指出:
“是的,因为您从中获取它的函数的签名中有“Create”。请参阅:documentation/CoreFoundation/”

最佳答案

您不拥有从 CGLayerGetContext 返回的上下文,因此不应释放它*。特别是,请参阅http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/writerid/cfGetRule有关 Core Foundation 中“获取”功能的信息。

*:至少,您不应该根据示例代码发布它。如果你先保留它(CGContextRetain(weird)),那么你应该有一个 CGContextRelease 来平衡它。

关于iphone - 无法释放 CGContextRef(上下文来自 CGLayer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4593709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com