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

后端 未结 3 1423
情歌与酒
情歌与酒 2020-12-13 21:12

The app crashes about 15 seconds after launching and XCode just breaks at an address and gives me a pop up that says \"Thread 6 com.apple.NSURLConnectionLoader: Program rece

相关标签:
3条回答
  • 2020-12-13 21:15

    Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

    (gdb) info malloc-history 0x543216
    

    Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

    See this article for more detailed instructions.

    0 讨论(0)
  • 2020-12-13 21:20

    The fix in the comment above didn't end up fixing it after all and it was still crashing at random times with almost no debug info.

    With the debugger connected to my iPhone it gave a different error to the emulator and I saw a reference to a NSURLCache object. I then remembered I had some old code left over from trying to fix a memory leak in the NSURLConnection object...

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

    and also in another class I had...

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

    Removing these fixed the problem and also explained to me why it was so hard to track down. This looks to me like a bug somewhere in Apple's code as it was a total pain to track down with almost no error messages.

    I hope that helps someone else.

    0 讨论(0)
  • 2020-12-13 21:34

    Thanks iamichi for your efforts in tracking down this bug. This fixed my issue.

    One thing to note:

    I removed the following code from my app just as you did:

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

    and placed the following code (didn't remove) in the application delegate:

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

    All is well. Thanks!

    0 讨论(0)
提交回复
热议问题