2

我在我的应用程序中使用 ARC 并因此出现新的崩溃:

malloc: *** error for object 0x17e9a5d0: double free
*** set a breakpoint in malloc_error_break to debug

为了弄清楚,我启用了 Zombie Objects ,原因是:

*** -[CFString release]: message sent to deallocated instance 0x15d183e0

我的代码:

Class myClass = NSClassFromString(classString);
SEL mySelector =  NSSelectorFromString(selectorString);
NSString *arg = @"arg";

NSMethodSignature *sig = [myClass methodSignatureForSelector:mySelector];
NSInvocation * myInvocation = [NSInvocation invocationWithMethodSignature:sig];

[myInvocation setTarget: myClass];
[myInvocation setSelector: mySelector];
[myInvocation setArgument:&arg atIndex:2];

NSString *result = nil;
[myInvocation retainArguments];
[myInvocation invoke];
[myInvocation getReturnValue: &result]; 

NSLog(@" Result String : %@ ",result);

出了什么问题?哪个 CFString ?? 感谢您的任何回复。

编辑:

造成的对象NSString *result。下一步如何纠正这个错误?

4

2 回答 2

3

result被调用传回时不会被保留。尝试

CFStringRef result;
[myInvocation retainArguments];
[myInvocation invoke];
[myInvocation getReturnValue:&result]; 
if (result)
    CFRetain(result);

NSLog(@" Result String : %@ ", (__bridge NSString *)result);
于 2013-10-16T04:07:05.573 回答
1

__unsafe__unretained NSString *result; ARC 不会对它做任何事情。

于 2013-10-16T04:09:49.510 回答