如何找到因缺少 NSAutoreleasePool 而发生泄漏的线程?
当我运行我的应用程序时,我收到此消息:
*** __NSAutoreleaseNoPool(): Object 0xadf5e50 of class __NSDate autoreleased with no pool in place - just leaking
我知道我需要在发生这种情况的线程开头创建一个 NSAutoreleasePool,但我不确定在我的代码中发生这种情况。是否可以设置一个断点,当有问题的对象自动释放时将被命中?
I'm getting this message when I run my app:
*** __NSAutoreleaseNoPool(): Object 0xadf5e50 of class __NSDate autoreleased with no pool in place - just leaking
I understand that I need to create an NSAutoreleasePool at the start of the thread that this is happening on, but I'm not sure where in my code this is happening. Is it possible to set a breakpoint that will be hit when the object in question is autoreleased?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 __NSAutoreleaseNoPool 上设置一个符号断点,然后查看当您点击它时您所在的线程。这可以使用 Xcode 断点导航器底部的 UI 来完成,或者如果您愿意,也可以在 GDB 命令行上输入以下命令来完成:break __NSAutoreleaseNoPool
You could set a symbolic breakpoint on __NSAutoreleaseNoPool and see which thread you're on when you hit it. This can be done using the UI at the bottom of Xcode's Breakpoint Navigator, or on the GDB command line if you prefer, by entering the command: break __NSAutoreleaseNoPool
来自 MallocStackLogging 上的 CocoaDev:
From CocoaDev on MallocStackLogging:
只需在线程的主函数中添加自动释放池就可以解决内存管理问题。
像这样
或者如果你想使用新的语法
无论如何,你应该检查所有由工厂方法创建的或由你明确自动发布的 NSDate 。下面列出了 NSDate 类的所有工厂方法
date
dateWithNaturalLanguageString:
dateWithString :
dateWithTimeIntervalSinceNow:
dateWithTimeInterval:sinceDate:
dateWithTimeIntervalSinceReferenceDate:
dateWithTimeIntervalSince1970:
来自Apple 文档)
Simply adding an autorelease pool in your main function of your thread should fix your memory management problem.
Like this
or if you want to use the new syntax
Anyway, you should check all the NSDate created by a factory method or expressly autoreleased by you. All the factory method for the class NSDate are listed below
date
dateWithNaturalLanguageString:
dateWithNaturalLanguageString:locale:
dateWithString:
dateWithTimeIntervalSinceNow:
dateWithTimeInterval:sinceDate:
dateWithTimeIntervalSinceReferenceDate:
dateWithTimeIntervalSince1970:
(from Apple documentation)