Big*_*igT 0 iphone xcode automatic-ref-counting
我在我的代码中使用ARC,我收到错误
Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Run Code Online (Sandbox Code Playgroud)
它打破的线是
return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class]));
Run Code Online (Sandbox Code Playgroud)
因为我使用ARC,所以不能NSAutoReleasePool像往常那样放置它.我可以使用什么来修复此错误?
您使用@autoreleasepool构造:
@autoreleasepool {
// main code here
}
Run Code Online (Sandbox Code Playgroud)
这创建了NSAutoReleasePool与括号相同的范围,并且它也可以在MRC代码中使用.它具有在发生异常时进行清理的优点,并且可以轻松地用于安全地分派线程.
要阅读更多内容,请访问有关转换为ARC发行说明的文章