我在我的应用程序中使用 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 导致 .下一步如何纠正这个错误?
Best Answer-推荐答案 strong>
result 在被调用传回时没有被保留。
试试
CFStringRef result;
[myInvocation retainArguments];
[myInvocation invoke];
[myInvocation getReturnValue:&result];
if (result)
CFRetain(result);
NSLog(@" Result String : %@ ", (__bridge NSString *)result);
关于ios - ARC下双倍免费,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/19394935/
|