为什么我的应用程序退出“SIGABRT”?

时间:2011-01-29 14:00:04

标签: iphone objective-c ios-simulator

我正在开发一个iPhone应用程序,它将从REST HTTP服务接收xml的杂货店购物清单。但是当我运行应用程序时,它会在模拟器中以SIGABRT退出。

我可以从堆栈跟踪中看到我在[NSAutoreleasePool发布]中,所以我猜这是一个内存管理问题。自动释放池的问题当然是很难追踪实际问题。

然而我发现它是由某种方式调用[NSURLConnection sendSynchronousRequest]引起的,因为如果我在调用之前放置我的return语句,那么我没有得到任何错误(除了没有数据)。如果我在sendSynchronousRequest之后放置我的return语句,那么我得到了SIGABRT。

这是函数

- (NSArray*)getShoppingListItems {
    NSString *escapedToken = [self.user.token URLEncodedString_ch];
    NSString *strUrl = [[NSString alloc] 
                        initWithFormat:@"http://www.denglademad.dk/shoppinglist/foruser/%@?token=%@",
                        self.user.userID, escapedToken];
    NSURL *url = [[NSURL alloc] initWithString:strUrl] ;
    NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];
    NSURLResponse *resp = nil;
    NSError *err = nil;
    // Returning [NSMutableArray array] does not cause SIGABRT
    NSData *response = [[NSURLConnection 
                        sendSynchronousRequest:urlRequest 
                        returningResponse: &resp
                        error: &err] retain];
    // Returning here does cause a SIGABRT
    return [NSMutableArray array]; 
    NSString *xml = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
    ShoppingListXmlParser *parser = [[ShoppingListXmlParser alloc] init];
    return [parser parseShoppingListXmlData:response];
}

我知道有很多内容应该发布,但是这是一个自动释放问题,我只是在绝望中暂时删除了每个发布/自动释放调用。

以下是调试器的输出。

...
Canceling call as the malloc lock is held so it isn't safe to call the runtime.
Issue the command:
    set objc-non-blocking-mode off 
to override this check if you are sure your call doesn't use the malloc libraries or the ObjC runtime.
(gdb) continue
DenGladeMad(619,0xa0c51540) malloc: *** error for object 0x4d3cd40: double free
*** set a breakpoint in malloc_error_break to debug
Program received signal:  “SIGABRT”.
(gdb) 

任何线索?

1 个答案:

答案 0 :(得分:2)

这通常是与释放未分配对象相关的错误。尝试在目标的可执行文件上设置NSZombieEnabled = YES。只需双击Xcode中的可执行文件,选择参数选项卡,然后在属性窗口下半部分的Environment Variables部分下设置它。这将在您下次在模拟器中点击它时在ogs中提供更多细节。

在构建和提交应用之前,请务必禁用此变量。打开时消耗了大量资源,因此您的应用程序将受到性能影响。

祝你好运!