Dan Rosenstark
Dan Rosenstark

Reputation: 69777

Is This a Memory Crash? NSZombies doesn't catch it

Is this definitely a memory crash, or should I be looking for something else?

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x81093cd0
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x33563f78 objc_msgSend + 16
1   Foundation                      0x34d6b92c __NSFireDelayedPerform + 408
2   CoreFoundation                  0x35919a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
3   CoreFoundation                  0x35919692 __CFRunLoopDoTimer + 358
4   CoreFoundation                  0x35918268 __CFRunLoopRun + 1200
5   CoreFoundation                  0x3589b49e CFRunLoopRunSpecific + 294
6   CoreFoundation                  0x3589b366 CFRunLoopRunInMode + 98
7   GraphicsServices                0x33636432 GSEventRunModal + 130
8   UIKit                           0x33073cce UIApplicationMain + 1074

Using the profiler, live bytes are well under 10MB at all times, and when memory warns happen I'm back to 3MB or below.

This statement returns YES, so I assume I have zombies enabled:

getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled")

When I'm running from Xcode, the app crashes without Xcode even being aware (after some arbitrary number of memory warns).

Any suggestions besides "run with NSZombies enabled?" And, is this definitely a memory crash?

Upvotes: 0

Views: 168

Answers (2)

Mats Petersson
Mats Petersson

Reputation: 129454

SIGSEGV happens when the code tries to access memory that "doesn't exist" (that is, the address you are trying to use doesn't have a mapping in your virtual address space).

The exact cause of this can be a large number of things - the most common ones are:

  • Using pointers that are not (properly) initialized.
  • Walking off the end of an array.
  • Using memory that has been freed.

Note that all of the above are examples of "undefined behaviour", so you may well have situations where your code doesn't crash although it's doing something wrong, but the same code, under other circumstances, DOES go wrong.

Upvotes: 2

user529758
user529758

Reputation:

Yes, this is a memory-related error (segmentation fault). Keep in mind that NSZombies can't catch every memory error.

Upvotes: 1

Related Questions