Search code examples
iphonensinvocation

How to properly release retained arguments of an NSInvocation?


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?


Solution

  • 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.
    

    Source: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSInvocation_Class/Reference/Reference.html

    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