ARC Autoreleased with no pool in place

百般思念 提交于 2019-12-10 11:58:05

问题


I am using ARC in my code and I am getting the error

Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

The line it breaks on is

  return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class]));

Since I am using ARC I cannot put an NSAutoReleasePool around it like I usually would. What can I use in order to fix this error?


回答1:


use this on the line where it showing the warning

@autoreleasepool{
}



回答2:


You use the @autoreleasepool construct:

@autoreleasepool {
    // main code here
}

This creates a NSAutoReleasePool with the same scope as the brackets, and it can also be used in MRC code as well. It has the advantages of being cleaned up when exceptions occur, and can easily be used to dispatch threads safely.

To read more, visit this article on Transitioning to ARC Release Notes




回答3:


Create a new test app with ARC enabled. Look at the code in "main.m" to see what Apple recommends.



来源:https://stackoverflow.com/questions/11227237/arc-autoreleased-with-no-pool-in-place

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!