Debugging memory on OS X
Just a short note so I don't have to Google around Apple's web site for hours: There's a few useful environment variables that can be set to help in debugging disposed memory accesses etc. Most of them are documented on Enabling the mallocDebug features and Finding memory leaks:
- Set DYLD_INSERT_LIBRARIES to /usr/lib/libMallocDebug.A.dylib. This makes you link against libMallocDebug, which prints errors on bad accesses. Set a breakpoint on MDprintf to see a backtrace when this triggers.
- set MallocScribble and MallocPreScribble to YES to initialize new memory to 0xAA and freed memory to 0x55, which will also help finding out when you're accessing bad memory.
- set MallocGuardEdges to YES to make it harder to smash memory and instead get a bad access exception.
Any other memory debug tricks you guys have?