CGLayerRef in NSValue - when to call retain() or release()?

前端 未结 1 1471
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 10:47

I am caching some graphics onto CGLayers and then storing them in NSValue objects using @encode (so as to store them in an array). I just wanted to make sure that I handle the r

相关标签:
1条回答
  • 2021-01-26 11:27

    NSValue doesn't know about Core Foundation types, so it will not retain or release the CGLayer. (The @encoded type string pretty much just tells it how big the value is; it does not tell it anything about memory management.)

    You must not release the layer until you are fully done with both the layer and the NSValue.

    Or, better yet, just put the CGLayer into the array. All Core Foundation objects are compatible with NSObjects for purposes of memory management (discussed previously), which has the practical effect that you can put CF objects into NSArrays and vice versa. Since CGLayers are CF objects, this means that you can put the CGLayer into the array without boxing it in another object.

    0 讨论(0)
提交回复
热议问题