Are the retained arguments released when the NSInvocation is deallocated, or do I need to do a release manually on the objects in the argument list of an NSInvocation?
2 Answers
The "retained arguments"? The arguments are not automatically retained by NSInvocation. See:
This class does not retain the arguments for the contained invocation by default. If those
objects might disappear between the time you create your instance of NSInvocation and the
time you use it, you should explicitly retain the objects yourself or invoke the
retainArguments method to have the invocation object retain them itself.
When you use "retainArguments" you don't have to manually release them again. NSInvocation does that for you by adding them to the autorelease pool. See: http://www.cocoabuilder.com/archive/cocoa/241994-surprise-nsinvocation-retainarguments-also-autoreleases-them.html

- 42,912
- 19
- 126
- 165
-
But you can have the invocation retain them by calling `retainArguments` method on it. – Deepak Danduprolu Jun 23 '11 at 06:04
-
This answer is accurate but not helpful. The OP is asking whether `retainArguments` also causes the NSInvocation to release them. – jtbandes Jun 23 '11 at 06:10
-
I've clarified my answer. From the question it wasn't obvious if he had used retainArguments or not. – Johannes Fahrenkrug Jun 23 '11 at 06:24
Via Google, I found this conversation, which explains the key reason why you don't need to release the arguments:
So I decided to -retainArguments, and presumed that this meant I was supposed to release the target and arguments when I was done with them.
As you've discovered, no, you're not supposed to do that. You have not retained the target and arguments. You have told the NSInvocation to do so, and it then has responsibility for releasing them.
(I'd also recommend you read the Memory Management Programming Guide for some other such patterns and insights.)

- 115,675
- 35
- 233
- 266