删除NSView的CAMetalLayer

时间:2018-11-27 14:53:19

标签: calayer nsview metal

我有一个自定义的NSView类,该类具有层支持。我为此CAMetalLayer创建的NSView做一个makeBackingLayer

makeBackingLayer中,我创建了一个图层CAMetalLayer *backingLayer = [CAMetalLayer layer];,并根据需要设置属性。

我的问题是,在销毁dealloc时是否需要明确地NSView一层? 我没有在覆盖函数中创建该层,是我有责任删除它还是由NSView来处理?

我没有看到任何与此相关的文档。而且,我看到的所有示例都没有提及删除任何地方的图层。

谢谢

1 个答案:

答案 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.