VisualVM - Find all references to a class
Asked Answered
H

2

13

I am attempting to debug a permgen error in an application. I am running VisualVM to profile the app and have taken a heapdump of the memory snapshot.

Loading the snapshot into VisualVM for analysis, I can currently see in the classes list several classes appearing several times, all listed with 0 instances, 0 size - I am only expecting one of these classes each (probably linked to its classloader) - Is there any way to determine what is still holding references to these classes with no instances? Happy to use another tool if I can just load in the dump(.hprof) to analyze what is holding the reference.

Thanks!

Hauteloire answered 15/1, 2013 at 15:51 Comment(1)
I have used YourKit for this in the past. It can load a dump. You can get a free eval license.Indoaryan
I
6

I use MAT for stuff like this. Works great, even on large heaps.

Impassive answered 15/1, 2013 at 15:56 Comment(1)
Thanks - just stumbled upon another recommendation for MAT also - have installed in Eclipse so will load in logs to see what I can find.Hauteloire
P
46

Well, saying "use MAT" doesn't really answer the question!

To do it in VisualVM, in the Sampler or Profiler view there is a button (top right) labeled "Heap Dump". Click this, which opens the heap analyser. Under the "Classes" tab, all loaded classes are shown. At the bottom there is a search box, type the class name you are interested in, in the filtered view double click the class in question.

This opens the instances view. Right-click an instance int the left pane, and select "Show Nearest GC Root" to find what is referencing the object.

Barney

Plessor answered 6/12, 2015 at 17:29 Comment(0)
I
6

I use MAT for stuff like this. Works great, even on large heaps.

Impassive answered 15/1, 2013 at 15:56 Comment(1)
Thanks - just stumbled upon another recommendation for MAT also - have installed in Eclipse so will load in logs to see what I can find.Hauteloire

© 2022 - 2024 — McMap. All rights reserved.