Knowing when autoreleased objects are returned



My question is somewhat generally about autoreleased objects but I’ll give a specific example, because I’ve encountered this a couple of times already in the book.

On page 263 under “Unarchiving objects” I see: “because the method returns an autoreleased object.”

Reading the documentation for NSKeyedUnarchiver’s unarchiveObjectWithFile: method, I find no discussion of memory management.

So how do you guys manage to know this stuff? :wink:

Is this something I should be able to deduce? [It’s not in the docs AFAIK and there’s no source code available, correct?]



We talk about this in the memory management chapter when we give the rules of memory management.

Basically, it boils down to this: if you don’t see alloc, new or copy in the name of the method, it is an autoreleased object that is being returned to you. While this is just a naming convention (that is, the compiler won’t check for you), it is a strictly enforced rule in all of Apple’s classes.


Hi, thanks for your quick response.

I do remember reading about that now. It’s covered under “Retain count rules” on Page 73.