Do you need to release parameters of methods at the end of them in Objective-C? Do you need to release parameters of methods at the end of them in Objective-C? objective-c objective-c

Do you need to release parameters of methods at the end of them in Objective-C?


No. Think NARC: "New Alloc Retain Copy". If you are not doing any of those things, you don't need to release.


Please read the Cocoa memory management guidelines. The following rule is relevant to your question:

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.

Clearly you did not obtain the parameters by creating them (in your method). So the only part that you need to worry about is whether you retained them in the method. If you did, you must release or autorelease them. If you did not, you must not release or autorelease them.


You need to release them only, if you retain them in your method. The convention is, that the caller is responsible to make sure, that the objects passed as arguments live at least as long as the call is active.