Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 466
rhinds Avatar asked Jan 15 '13 15:01

rhinds


2 Answers

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

like image 166
barneypitt Avatar answered Nov 05 '22 04:11

barneypitt


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

like image 28
K Erlandsson Avatar answered Nov 05 '22 04:11

K Erlandsson