GHUnit Environment Variables
Go into the "Get Info" contextual menu of your (Tests) executable (inside the "Executables" group in the left panel of XCode). Then go in the "Arguments" tab. You can add the following environment variables:
GHUNIT_CLI - Default NO; Runs tests on the command line (see Debugger Console, Cmd-Shift-R)
GHUNIT_RERAISE - Default NO; If an exception is encountered it re-raises it allowing you to crash into the debugger
GHUNIT_AUTORUN - Default NO; If YES, tests will start automatically
GHUNIT_AUTOEXIT - Default NO; If YES, will exit upon test completion (no matter what); For command line MacOSX testing
Test Environment Variables (Recommended)
Go into the "Get Info" contextual menu of your (Tests) executable (inside the "Executables" group in the left panel of XCode). Then go in the "Arguments" tab. You can add the following environment variables:
Environment Variable: Default: Set to:
NSDebugEnabled NO YES
NSZombieEnabled NO YES
NSDeallocateZombies NO NO (or YES)
NSHangOnUncaughtException NO YES
NSAutoreleaseFreedObjectCheckEnabled NO YES
If Using NSDeallocateZombies=NO, then all objects will leak so be sure to turn it off when debugging memory leaks.
For more info on these varaiables see NSDebug.h (http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html)
For malloc debugging:
MallocStackLogging
MallocStackLoggingNoCompact
MallocScribble
MallocPreScribble
MallocGuardEdges
MallocDoNotProtectPrelude
MallocDoNotProtectPostlude
MallocCheckHeapStart
MallocCheckHeapEach
If you see a message like:
2009-10-15 13:02:24.746 Tests[38615:40b] *** -[Foo class]: message sent to deallocated instance 0x1c8e680
Re-run (in gdb) with MallocStackLogging=YES
(or MallocStackLoggingNoCompact=YES
), then if you run under gdb:
(gdb) shell malloc_history 38615 0x1c8e680
ALLOC 0x1a9ad10-0x1a9ad6f [size=96]: thread_a024a500 |start | main | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __NSThreadPerformPerform | -[GHTestGroup _run:] | -[GHTest run] | +[GHTesting runTest:selector:withObject:exception:interval:] | -[Foo foo] | +[NSObject alloc] | +[NSObject allocWithZone:] | _internal_class_createInstance | _internal_class_createInstanceFromZone | calloc | malloc_zone_calloc
Somewhere between runTest and NSObject alloc there may be an object that wasn't retained.
Also using MallocScribble=YES
causes the malloc library to overwrite freed memory with a well-known value (0x55), and occasionally checks freed malloc blocks to make sure the memory has not been over-written overwritten written since it was cleared.
For more info on these variables see MallocDebug (http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html)
For more info on malloc_history see malloc_history (http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/malloc_history.1.html)