开发者

Is this a correct summary of Cocoa reference counting?

开发者 https://www.devze.com 2022-12-21 09:57 出处:网络
Here\'s my understanding of it: Object are only retained (reference counter is incremented): when init from NSObject is ca开发者_C百科lled.

Here's my understanding of it:

Object are only retained (reference counter is incremented):

  1. when init from NSObject is ca开发者_C百科lled.
  2. when retain is called.

Objects are only released (reference counter is decremented):

  1. when release is called.
  2. when an autorelease pool containing the object is drained

And to clarify, autorelease does not retain, but just places the object into the top most pool on the autorelease pool stack.


No.

init does not retain, and there are various methods you didn’t mention which do. There is a simple (and also correct) summary in Memory Management Programming Guide for Cocoa.

(There are two exceptions that I’m aware of: the NSPropertyListSerialization methods which provide a retained error string by reference.)

0

精彩评论

暂无评论...
验证码 换一张
取 消