rhinds
rhinds

Reputation: 10043

VisualVM - Find all references to a class

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!

Upvotes: 13

Views: 11496

Answers (2)

barneypitt
barneypitt

Reputation: 1182

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

Upvotes: 46

K Erlandsson
K Erlandsson

Reputation: 13696

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

Upvotes: 6

Related Questions