I'm using jvisualvm
to check for memory leaks in my application. When I do a heap dump, sometimes several objects are being held open that should have been garbage collected.
When I do a "Show Nearest GC Root" command on them, it shows me that the root is a class which I defined which implements the interface Runnable. The reference is listed as (java frame)
, which I know has something to do with threading. When I expand the tree for this node, it opens up and shows <no references>
. So it seems pretty clear that this is not a reference I'm keeping open, but something internal to Java.
The GC Root object listed in jvisualvm is of type AnalyticNode extends Node
which in turn is Node implements Runnable
. This root object in no way has anything to do with AWT, Swing, or any heavyweight user interface components, despite the word "frame" being used. In this case, the word "frame" refers to threading.
So does Java keep a reference to the last Runnable somewhere that would be holding this open? Is there any way that I can tell Java to release this reference so it can be properly garbage collected for my heap dump?
What's going on here?