views:

44

answers:

2

Hi,

The Cocoa "Memory Management Programming Guide" document says:

You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects you own using release or autorelease. Any other time you receive an object, you must not release it.

Does this also apply to the convenience methods like [NSNumber numberWithFloat:] or [CAAnimation animation]? Should I release these or not?

Thanks!

+2  A: 

That statement is still true for convenience methods, in particular the last sentence

Any other time you receive an object, you must not release it.

This means that you must not release these objects unless you explicitly send them a retain message beforehand.

Claus Broch
That means they're autoreleased, right? Thanks!
Kay
@Kay: Yes, they are autoreleased when they are returned from the convenience methods.
Claus Broch
No, it means you don't have ownership of them and you should thus not release them. How their owners choose to manage their memory (retain+autorelease or not) is none of your concern.
Barry Wark
+1  A: 

Those method names do not begin with alloc or new, nor contain copy, nor are they retain. So, no—you do not own the objects those methods return, so you should not release them.

Peter Hosey