0

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?

4

3 回答 3

2

您可以在 __NSAutoreleaseNoPool 上设置一个符号断点,并在您点击它时查看您在哪个线程上。这可以使用 Xcode 断点导航器底部的 UI 来完成,或者如果您愿意,可以在 GDB 命令行上输入以下命令:break __NSAutoreleaseNoPool

于 2011-10-10T15:43:46.757 回答
1

来自 MallocStackLogging 上的CocoaDev

这是一个环境变量。设置此环境变量后,在 tcsh 中使用“setenv MallocStackLogging 1”(例如),然后您可以在该 shell 中启动任何应用程序。不要“打开”应用程序,从外壳启动它。当你这样做时,所有的 malloc 都会被跟踪。然后说,在另一个外壳中,“泄漏”或“泄漏”将为您提供当时应用程序中潜在的大量泄漏列表。

然后,您可以循环执行一系列操作,并查看迭代之间的泄漏数量是否发生变化。泄漏有一个 id,它在应用程序的生命周期内保持不变,大小和有时对被泄漏对象类型的猜测,以及泄漏数据的开始位的转储。

弄清楚如何最好地修复泄漏,以及如何解释您在泄漏转储中看到的一些内容是另一回事。

于 2011-10-10T15:24:04.597 回答
0

只需在线程的主要功能中添加一个自动释放池即可解决您的内存管理问题。像这样

- (void)main
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    ...
    Your code here
    ...

    [pool release];
}

或者如果您想使用新语法

- (void)main
{
    @autoreleasepool {
        ... your code here ...
    }
}

无论如何,您应该检查所有由工厂方法创建或由您明确自动发布的 NSDate。下面列出了 NSDate 类的所有工厂方法

  • 日期

  • dateWithNaturalLanguageString:

  • dateWithNaturalLanguageString:语言环境:

  • 日期与字符串:

  • dateWithTimeIntervalSinceNow:

  • dateWithTimeInterval:sinceDate:

  • dateWithTimeIntervalSinceReferenceDate:

  • dateWithTimeIntervalSince1970:

(来自苹果文档

于 2011-10-10T15:31:29.933 回答