If I have a parameter passed to a method, do I need to release the parameter at the end of the method?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With