Here's my understanding of it:
Object are only retained (reference counter is incremented):
- when
init
fromNSObject
is ca开发者_C百科lled. - when
retain
is called.
Objects are only released (reference counter is decremented):
- when
release
is 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.)
精彩评论