我有一个自定义的NSView
类,该类具有层支持。我为此CAMetalLayer
创建的NSView
做一个makeBackingLayer
。
在makeBackingLayer
中,我创建了一个图层CAMetalLayer *backingLayer = [CAMetalLayer layer];
,并根据需要设置属性。
我的问题是,在销毁dealloc
时是否需要明确地NSView
一层?
我没有在覆盖函数中创建该层,是我有责任删除它还是由NSView来处理?
我没有看到任何与此相关的文档。而且,我看到的所有示例都没有提及删除任何地方的图层。
谢谢
答案 0 :(得分:1)
You likely do not need to manually free your layer. Assuming your program has ARC (Automatic Reference Counting) enabled, your NSView
should automatically free whichever CALayer
is set to its .layer
property upon its destruction.
If you're not sure if ARC is enabled, you can go to Build Settings in your Xcode project and search for Automatic Reference Counting. It's been on by default for new Xcode projects for several years now.
Note: Your NSView
will only be able to free your layer if it is the only object holding a reference to it. If other objects in your program are holding references to your CAMetalLayer
, your layer would not be freed until they remove their references.