interpreting NSZombies and malloc_history
interpreting NSZombies and malloc_history
- Subject: interpreting NSZombies and malloc_history
- From: Jeffrey Oleander <email@hidden>
- Date: Tue, 14 Sep 2010 17:30:52 -0700 (PDT)
I have a little program that's a small part of another project but have it implemented separately to work it out. It involves several mutable arrays (one of them is an array of arrays), and a couple sets. I create a few temporary objects solely for testing whether an item with the same value is already a member of one of the sets. Over time, they're added to the "active" set, and then taken out of that to the "done" set.
All of which is to say that even in this small test (only 16 nodes), I do a fair amount of allocing and releasing. And most of the time I use some enumerators to traverse the arrays. I also understand that within each such enumeration loop, the enumeration set-up does a retain and autorelease on each object from the array it visits. That's OK, for now. I release the enumerators when I'm done with them, have quadruple checked by eye-ball my own retains and releases which are almost all in nice balanced scenarios (the small number of cases which require special handling include a search method which has to find a particular object, and return it to the sender).
I had the output merely going to the debugger log and once that looked OK, I wired up a table view.
The window loads, and I have a button to tell it to build the primary mutable array (this will be coming from a document file eventually, but this also gave me a chance to make sure the environment vars and breakpoints were all in place before it began before I found out I didn't have to type them all in as commands in the debugger console), then enter a couple parameters and have it scour the array and build a smaller one, a sort of critical path between 2 nodes.
After that action method is complete and it pops back up the stack a couple layers to the mouse event, the call stack suddenly changes and I get Program received signal: "EXC_BAD_ACCESS" when it releases its autorelease pool, so I figure I'm over-releasing something. I'm not explicitly allocating my own autorelease pools. Thinking I need help with the Cocoa end of things, I posted a question yesterday on Cocoa-dev. One of the responses convinced me what I need just now is help with the tools, understanding the output they generate.
So, I did some more searching and found some enlightening posts by Jon Hess and James Bucanek. I set environment variables for the executable via the Xcode GUI and using copy and paste:
MallocHelp=NO
NSZombieEnabled=YES
NSDeallocateZombies=NO
MallocCheckHeapEach=100000
MallocCheckHeapStart=100000
MallocScribble=YES
MallocStackLogging=YES
MallocStackLoggingNoCompact=YES
MallocGuardEdges=YES
MallocCheckHeapAbort=1
(though not all of those in every experiment, I did have them set this way when I got the info, pasted below).
created new break-points via the Xcode GUI:
-[_NSZombie retainCount]
-[_NSZombie retain]
-[_NSZombie release]
-[_NSZombie methodSignatureForSelector:]
-[_NSZombie respondsToSelector:]
-[_NSZombie class]
szone_error
The first Autorelease error was triggered after initialization of the data-structures.
...
2010-09-14 18:21:58.123 DijkstraCocoa[649] MyDocument createGraph: done
2010-09-14 18:22:06.828 DijkstraCocoa[649] *** *** Selector 'release' sent to dealloced instance 0x57f9a0 of class NSIdEnumerator.
Break at '-[_NSZombie release]' to debug.
2010-09-14 18:22:06.868 DijkstraCocoa[649] *** -[NSAutoreleasePool dealloc]: Exception ignored while releasing an object in an autorelease pool: NSGenericException *** Selector 'release' sent to dealloced instance 0x57f9a0 of class NSIdEnumerator.
Break at '-[_NSZombie release]' to debug.
(gdb) shell malloc_history 649 0x57f9a0
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | 0x90aa5608 | 0x90a8b238 | 0x901d5574 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | 0x90aa5608 | 0x90a8b238 | 0x901d55b4 | 0x901c1880 | malloc_zone_free
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79d68 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79ed0 | 0x901c1880 | malloc_zone_free
Call [2] [arg=64]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90a26510 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90a2586c | 0x90a2752c | malloc_zone_free
Call [2] [arg=32]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79e00 | 0x90212684 | 0x901cf4f4 | 0x901cdab0 | 0x901c6ed0 | 0x901d4494 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79e00 | 0x90212684 | 0x901cf6bc | 0x901cdab0 | 0x901c6fac | malloc_zone_free
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b238 | 0x901d5574 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b238 | 0x901d55b4 | 0x901c1880 | malloc_zone_free
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79d68 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79ed0 | 0x901c1880 | malloc_zone_free
Call [2] [arg=24]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument createGraph:] | -[MyDocument logGraph] | 0x90a26564 | 0x90a221ec | 0x90861b30 | malloc_zone_calloc
(gdb) continue
Current language: auto; currently objective-c
Then I continued, entered my parameters and told it to do its analysis, and, once again while popping up the call chain it kicked out:
2010-09-14 18:23:38.116 DijkstraCocoa[649] MyDocument findRelationship: ---display path---
2010-09-14 18:23:46.191 DijkstraCocoa[649] displayResults: resultsField=<NSTableView: 0x547320>
2010-09-14 18:23:50.169 DijkstraCocoa[649] displayResults: superView=<NSClipView: 0x547dd0>, superSuperView=<NSScrollView: 0x547ec0> window=<NSWindow: 0x54ed20>
(gdb) continue
2010-09-14 18:24:03.942 DijkstraCocoa[649] MyDocument findRelationship: --- DONE ---
2010-09-14 18:24:21.705 DijkstraCocoa[649] *** *** Selector 'release' sent to dealloced instance 0x593e60 of class NSIdEnumerator.
Break at '-[_NSZombie release]' to debug.
2010-09-14 18:24:21.720 DijkstraCocoa[649] *** -[NSAutoreleasePool dealloc]: Exception ignored while releasing an object in an autorelease pool: NSGenericException *** Selector 'release' sent to dealloced instance 0x593e60 of class NSIdEnumerator.
Break at '-[_NSZombie release]' to debug.
(gdb) shell malloc_history 649 0x593e60
Call [2] [arg=443]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79e50 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79f4c | malloc_zone_free
Call [2] [arg=32]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | -[JGPriorityQ logPriorityQ] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79e00 | 0x90212684 | 0x901cf4f4 | 0x901cdab0 | 0x901c6ed0 | 0x901d4494 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | -[JGPriorityQ logPriorityQ] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79e00 | 0x90212684 | 0x901cf6bc | 0x901cdab0 | 0x901c6fac | malloc_zone_free
Call [2] [arg=88]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | -[JGPriorityQ logPriorityQ] | 0x90aa5608 | 0x90a8b238 | 0x901d55a8 | 0x901c8494 | 0x901c5d00 | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | -[JGPriorityQ logPriorityQ] | 0x90aa5608 | 0x90a8b2bc | 0x901c1880 | malloc_zone_free
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b238 | 0x901d5574 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b238 | 0x901d55b4 | 0x901c1880 | malloc_zone_free
Call [2] [arg=28]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79d68 | 0x901d62bc | 0x901c2a24 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2a8 | 0x90a79ed0 | 0x901c1880 | malloc_zone_free
Call [2] [arg=195]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b25c | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2b4 | malloc_zone_free
Call [2] [arg=128]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b238 | 0x901d559c | 0x901cf7f4 | 0x901d7750 | 0x901c6ed0 | 0x901d4494 | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b238 | 0x901d55b4 | 0x901c1848 | 0x901cb628 | malloc_zone_free
Call [2] [arg=201]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b25c | malloc_zone_malloc
Call [4] [arg=0]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90aa5608 | 0x90a8b2b4 | malloc_zone_free
Call [2] [arg=24]: thread_a000b2a4 |0x1 | _dyld_start | start | main | 0x973c0764 | 0x9730406c | 0x972fbc3c | 0x97309590 | 0x97395490 | 0x973d02bc | 0x9735f0ec | 0x973bf6a0 | 0x973853c0 | 0x9737e698 | -[MyDocument findRelationship:] | 0x90a26564 | 0x90a221ec | 0x90861b30 | malloc_zone_calloc
(gdb) continue
But the results in the GUI for the program at that point in time look copacetic, so I did a normal command-Q
Debugger stopped.
Program exited with status value:0.
So, what I don't know is how to read this malloc_history.
Obviously, the hex values are addresses, but the addresses in the history are not close to the address where it told me to look.
The methods named logWhatever are dumping structure contents to the Debugging Log, and, perhaps, it creates temporary objects while doing those NSLog statements to get values to format and record. And it does use iterators to walk the arrays, but I'm not doing any explicit allocating or releasing of my own in those routines.
I'm running on 10.3.9, Xcode 1.5 (and no, I don't have a pile of dough socked away to be buying new hardware so I can buy and run new software; until the Bush-Clinton-Bush-Obama economic depression ends or I fall into a gold-mine this is all I have to work with).
What additional/different info should I include to be able to get better responses?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden