帮助查看崩溃日志
当 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: 9Crashed Thread: 7
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes:
KERN_INVALID_ADDRESS at 0x0000000000000010Application Specific Information: objc[14187]: garbage collection is
OFFThread 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建具有绑定生命周期和显式作用域的自动释放池。
在这种情况下,您将自动释放池存储在 ivar 中(假设)。
只需将其设置为方法本地即可,如下所示:
通常引入的问题是:
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:
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
不幸的是,自动释放池崩溃是最难调试的。从静态分析器开始,它可以找到一些东西。
然后打开 NSZombies。
您的
XmlWrapper
对象有点奇怪。为什么一创建就立即释放呢?这是 NSURLConnection 的包装吗?您仍然应该保留该对象,以便在释放该对象时可以取消它或清除其委托。确保您对所有 ivars 使用访问器,而不是直接访问它们。根据我的经验,在
init
和dealloc
之外直接访问 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 aroundNSURLConnection
? 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
anddealloc
is the #1 cause of these kinds of crashes in my experience.