I have not done this myself, but I use the Insane library to do leak testing on my code base (and it's been used successfully for leak testing in NetBeans for years).
Here's the Insane library: http://performance.netbeans.org/insane/index.html Here's a blog entry I wrote about using it for unit tests outside the NetBeans code base: http://blogs.sun.com/tor/entry/leak_unit_tests If you look at the source code for the unit testing framework, you'll see that it uses Insane not just to walk the heap to discover the GC roots for a given reference, it also has unit test assertions for ensuring that the transitive closure of a reference does not exceed a certain memory size, etc. I suspect you can use Insane, possibly with a modified version of the GC root walker, to do some programmatic traversal of your circular data structure and make some assertions along the way to detect where you're doing something you didn't expect (e.g. let's say you don't want any references through a static hashmap or something). Also, this might be a useful trick -- this is from Solaris' dtrace utility's source code ( http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/dtrace/dtrace.c ) /* * We want to have a name for the minor. In order to do this, * we need to walk the minor list from the devinfo. We want * to be sure that we don't infinitely walk a circular list, * so we check for circularity by sending a scout pointer * ahead two elements for every element that we iterate over; * if the list is circular, these will ultimately point to the * same element. You may recognize this little trick as the * answer to a stupid interview question -- one that always * seems to be asked by those who had to have it laboriously * explained to them, and who can't even concisely describe * the conditions under which one would be forced to resort to * this technique. Needless to say, those conditions are * found here -- and probably only here. Is this is the only * use of this infamous trick in shipping, production code? * If it isn't, it probably should be... */ -- Tor On Jun 14, 8:42 am, Jan Goyvaerts <[email protected]> wrote: > Hi ! > > I'm having a particular problem of circular object referencing. I've got a > HUGE pile of objects and ONE object I know is part of a circular > relationship. > > The problem is that I just can't manually follow all the references from > that object until I'm getting the original object. There's just way too much > data to look for. > > So I thought running an OQL query on a heap dump would do the trick. Alas, > such a query is recursive and quite complex. It's about path finding really. > :-) > > Has anyone in here already successfully tackled such a problem ? > > Thanks in advance !!! > > Jan -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
