views:

58

answers:

1

Here's my understanding of it:

Object are only retained (reference counter is incremented):

  1. when init from NSObject is called.
  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.

+3  A: 

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.)

Ahruman
The NSPropertyListSerialization docs explicitly tell you that the method in question is breaking the rules, too.
Chuck
Another good summary is in Cocoa Core Competencies: http://developer.apple.com/mac/library/documentation/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html
Peter Hosey
As is Peter's own http://boredzo.org/cocoa-intro/
Rob Keniger
Thank you all :)
Sam Washburn