“Thread 6 com.apple.NSURLConnectionLoader:Program received signal:EXC_BAD_ACCESS”

时间:2011-10-18 23:22:32

标签: iphone objective-c ios xcode exc-bad-access

应用程序在启动后大约15秒崩溃,XCode刚刚在地址处断开,并弹出一个“Thread 6 com.apple.NSURLConnectionLoader:Program received signal:EXC_BAD_ACCESS”

我完全无法追踪问题。它在iOS 4上运行良好,但我猜这只是因为它更容忍bug或者其他东西。我已经尝试过在任何地方设置断点并逐步完成,在Zombies配置文件中的Instruments中运行它,但它只是炸弹而不告诉我在哪里。我没有警告和干净的分析,所以我有点不知所措。任何人都可以提供任何建议吗?感谢。

回溯是:

(gdb) backtrace
#0  0x024fb939 in _dispatch_retain ()
#1  0x024fbc02 in dispatch_source_cancel ()
#2  0x0109e492 in _CFURLCacheDeallocate ()
#3  0x0205a4e3 in CFRelease ()
#4  0x010331b1 in HTTPProtocol::~HTTPProtocol ()
#5  0x0100c75d in CFClass::FinalizeObj ()
#6  0x0205a4e3 in CFRelease ()
#7  0x02110af0 in __CFDictionaryStandardReleaseValue ()
#8  0x020714b1 in __CFBasicHashDrain ()
#9  0x0205a4e3 in CFRelease ()
#10 0x01024237 in SocketStream::~SocketStream ()
#11 0x0100c75d in CFClass::FinalizeObj ()
#12 0x0205a4e3 in CFRelease ()
#13 0x01023e0b in SocketStream::finalize ()
#14 0x01023dc6 in virtual thunk to SocketStream::finalize(void const*) ()
#15 0x01023da1 in ReadStreamCallbacks::_finalize ()
#16 0x0208201a in __CFStreamDeallocate ()
#17 0x0205a4e3 in CFRelease ()
#18 0x01030a6c in HTTPReadFilter::~HTTPReadFilter ()
#19 0x0100c75d in CFClass::FinalizeObj ()
#20 0x0205a4e3 in CFRelease ()
#21 0x010c22bc in non-virtual thunk to HTTPReadFilter::readStreamFinalize(__CFReadStream*) ()
#22 0x0102ff1c in CFNetworkReadStream::httpStreamFinalize ()
#23 0x0208201a in __CFStreamDeallocate ()
#24 0x0205a4e3 in CFRelease ()
#25 0x0103070f in NetConnection::shutdownConnectionStreams ()
#26 0x010bf1fc in NetConnection::closeStreamsIfPossibleOrSignalThatThatNeedsToBeDonePrettyPlease ()
#27 0x0103485b in HTTPConnectionCacheEntry::removeUnauthConnection ()
#28 0x010d6d2d in HTTPConnectionCacheEntry::purgeIdleConnections ()
#29 0x010d3c1e in ConnectionCacheTLS::resetCacheForThisThread ()
#30 0x0101b739 in ConnectionTimerTLS::_timerPurgeEntries ()
#31 0x02122966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#32 0x02122407 in __CFRunLoopDoTimer ()
#33 0x020857c0 in __CFRunLoopRun ()
#34 0x02084db4 in CFRunLoopRunSpecific ()
#35 0x02084ccb in CFRunLoopRunInMode ()
#36 0x00206e40 in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#37 0x001184e6 in -[NSThread main] ()
#38 0x00118457 in __NSThread__main__ ()
#39 0x98d6b259 in _pthread_start ()
#40 0x98d6b0de in thread_start ()

3 个答案:

答案 0 :(得分:8)

在调试器中设置NSZombieEnabledMallocStackLoggingguard malloc。然后,当您的应用程序崩溃时,请在gdb控制台中输入:

(gdb) info malloc-history 0x543216

0x543216替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它可以帮助您查明代码中导致问题的确切行。

See this article for more detailed instructions.

答案 1 :(得分:6)

感谢iamichi为您追踪此错误所做的努力。这解决了我的问题。

有一点需要注意:

我从我的应用中删除了以下代码:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

并在应用程序委托中放置以下代码(未删除):

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];

一切都很好。谢谢!

答案 2 :(得分:5)

上面评论中的修复程序并没有最终修复它,并且它几乎没有调试信息随机时间崩溃。

将调试器连接到我的iPhone后,它给模拟器带来了不同的错误,我看到了对NSURLCache对象的引用。然后我记得我在NSURLConnection对象中尝试修复内存泄漏时遗留了一些旧代码......

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

还有另一堂课......

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];

删除这些解决了这个问题,并向我解释了为什么追踪这么难。这在我看来就像是苹果公司代码中的一个错误,因为几乎没有任何错误消息追踪是一件非常痛苦的事情。

我希望能帮到别人。