帮助查看崩溃日志

发布于 2024-12-01 16:28:59 字数 1771 浏览 3 评论 0原文

当 Lion 从睡眠中醒来时,我的应用程序崩溃了。 问题似乎出在正在寻找天气信息的后台线程上。 我不确定,但我认为崩溃日志告诉我自动释放池正在弹出不再存在的对象,有人可以帮我确认这一点吗?

以下是崩溃日志的相关详细信息:

进程:myApp [14187] 标识符:myApp 版本:
??? (???) 代码类型:X86-64(本机)父进程:launchd [224]

日期/时间:2011-08-24 18:58:00.581 -0400 操作系统版本:Mac OS X 10.7.1 (11B26) 报告版本:9

崩溃的线程:7

异常类型:EXC_BAD_ACCESS (SIGSEGV) 异常代码: KERN_INVALID_ADDRESS 位于 0x0000000000000010

应用程序特定信息:objc[14187]:垃圾收集是 关闭

线程 7 崩溃:0 libobjc.A.dylib
0x00007fff9321700b(匿名 命名空间)::AutoreleasePoolPage::pop(void*) + 385 1
com.apple.CoreFoundation 0x00007fff961306a5 CFAutoreleasePoolPop + 37 2 com.apple.Foundation
0x00007fff969350d7 -[NSAutoreleasePool 排水] + 154 3
com.piso13.opusDomini 0x00000001000acb91 -[天气 内部开始] + 417 4 com.apple.Foundation
0x00007fff9698b1ea -[NSThread 主] + 68 5 com.apple.Foundation
0x00007fff9698b162 NSThread
_main + 1575 6 libsystem_c.dylib
0x00007fff90b068bf _pthread_start + 335 7 libsystem_c.dylib
0x00007fff90b09b75 thread_start + 13

这是我的天气内部启动代码:

-(void)internalStart{
    pool = [[NSAutoreleasePool alloc] init];

    forecast = FALSE;
    liveweather = FALSE;

    NSString *query = [self generateQuery];
    if (query == nil) {
        [pool drain];
        return;
    }


    XmlWrapper * xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:@"liveweather"];
    [xmlWrapper release];

    query = [self generateForecastQuery];
    xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:@"forecast"];
    [xmlWrapper release];

    [pool drain];

}

我是否应该调用 [pool duck] ?

My app is crashing on Lion when it awakes from sleep.
The problem seems to be with a background thread that is looking for weather info.
I'm not sure but I think the crash log is telling me that the autorelease pool is popping objects that are no longer there, can someone help me confirm this?

Here is the relevant details for the Crash log:

Process: myApp [14187] Identifier: myApp Version:
??? (???) Code Type: X86-64 (Native) Parent Process: launchd
[224]

Date/Time: 2011-08-24 18:58:00.581 -0400 OS Version: Mac OS
X 10.7.1 (11B26) Report Version: 9

Crashed Thread: 7

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes:
KERN_INVALID_ADDRESS at 0x0000000000000010

Application Specific Information: objc[14187]: garbage collection is
OFF

Thread 7 Crashed: 0 libobjc.A.dylib
0x00007fff9321700b (anonymous
namespace)::AutoreleasePoolPage::pop(void*) + 385 1
com.apple.CoreFoundation 0x00007fff961306a5
CFAutoreleasePoolPop + 37 2 com.apple.Foundation
0x00007fff969350d7 -[NSAutoreleasePool drain] + 154 3
com.piso13.opusDomini 0x00000001000acb91 -[Weather
internalStart] + 417 4 com.apple.Foundation
0x00007fff9698b1ea -[NSThread main] + 68 5 com.apple.Foundation
0x00007fff9698b162 NSThread
_main + 1575 6 libsystem_c.dylib
0x00007fff90b068bf _pthread_start + 335 7 libsystem_c.dylib
0x00007fff90b09b75 thread_start + 13

Here is my code for Weather Internal Start:

-(void)internalStart{
    pool = [[NSAutoreleasePool alloc] init];

    forecast = FALSE;
    liveweather = FALSE;

    NSString *query = [self generateQuery];
    if (query == nil) {
        [pool drain];
        return;
    }


    XmlWrapper * xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:@"liveweather"];
    [xmlWrapper release];

    query = [self generateForecastQuery];
    xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:@"forecast"];
    [xmlWrapper release];

    [pool drain];

}

Should I even be calling [pool drain] ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念 2024-12-08 16:28:59

创建具有绑定生命周期和显式作用域的自动释放池。

在这种情况下,您将自动释放池存储在 ivar 中(假设)。

只需将其设置为方法本地即可,如下所示:

- (void)internalStart
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    //...
    [pool drain], pool = nil;
}

通常引入的问题是:

1)自动释放池是基于堆栈的(池被推送和弹出)。如果按住它,您很容易打乱堆叠顺序。

2) 如果此类在多线程上下文中运行,则当您从多个线程推送和弹出池时,您可以轻松泄漏池或破坏堆栈顺序。

3)你也可以在多线程上下文中泄漏池

create your autorelease pools with bound lifetimes and explicit scopes.

in this case, you store your autorelease pool in an ivar (presumed).

just make it local to the method, like so:

- (void)internalStart
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    //...
    [pool drain], pool = nil;
}

the problems that are typically introduced are:

1) autorelease pools are stack based (pools are pushed and popped). by holding onto it, you can easily mess up the stack order.

2) if this class operates in a multithreaded context, you can easily leak pools or destroy the stack order when you push and pop pools from multiple threads.

3) you could also leak pools in multithreaded contexts

悲喜皆因你 2024-12-08 16:28:59

不幸的是,自动释放池崩溃是最难调试的。从静态分析器开始,它可以找到一些东西。

然后打开 NSZombies

您的 XmlWrapper 对象有点奇怪。为什么一创建就立即释放呢?这是 NSURLConnection 的包装吗?您仍然应该保留该对象,以便在释放该对象时可以取消它或清除其委托。

确保您对所有 ivars 使用访问器,而不是直接访问它们。根据我的经验,在 initdealloc 之外直接访问 ivars 是导致此类崩溃的第一大原因。

Unfortunately, autoreleasepool crashes are some of the hardest to debug. Start with the static analyzer, which can find some things.

Then turn on NSZombies.

Your XmlWrapper object is a bit strange. Why do you immediately release it as soon as you create it? Is this a wrapper around NSURLConnection? You should still hold onto the object so that you can cancel it or clear its delegate when this object is released.

Make sure you're using accessors for all your ivars rather than accessing them directly. Direct access to ivars outside of init and dealloc is the #1 cause of these kinds of crashes in my experience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文