当 NSInvocation 被释放时,保留的参数是否被释放,或者我是否需要在 NSInvocation 的参数列表中的对象上手动释放?

最佳答案

“保留的论据”? NSInvocation 不会自动保留这些参数。看:

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.

资料来源:http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSInvocation_Class/Reference/Reference.html

当您使用“retainArguments”时,您不必再次手动释放它们。 NSInvocation 通过将它们添加到自动释放池来为您完成。参见:http://www.cocoabuilder.com/archive/cocoa/241994-surprise-nsinvocation-retainarguments-also-autoreleases-them.html

关于iphone - 如何正确释放 NSInvocation 的保留参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6449855/

10-10 20:42