Is this a correct summary of Cocoa reference counting?
Here's my understanding of it:
Object are only retained (reference counter is incremented):
- when
initfromNSObjectis ca开发者_C百科lled. - when
retainis called.
Objects are only released (reference counter is decremented):
- when
releaseis called. - 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.)
加载中,请稍侯......
精彩评论