Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find culprit class/object by looking at memory profiler result in visualVM

I am profiling my Java application using VisualVM and I have gone through

profiling_with_visualvm_part_1

profiling_with_visualvm_part_2

When I see memory profile result, I see millions of Objects[], Char[], String and other such fundamental objects created which is taking all the memory. I want to know which of my classes (or my code) are actually responsible for creating those Objects[] and String etc, so far I couldn't find it. Once I know the culprit class I can dive-in the code and fix it.

I put a filter com.mypackage.*, but I see all of them are many times smaller (sometimes 0byte) compared to the total size of Objects[],Char[], String objects.

I believe, there should be a way to find the culprit code. Otherwise, profiler won't be of much use.

Let me know if my question is not clear, I will try to clarify further.

like image 728
Watt Avatar asked Sep 09 '13 17:09

Watt


1 Answers

If you want to see, which code allocates those instances, go to 'Memory settings' and enable 'Record allocations stack traces'. 'Record allocations stack traces' option is explained 'Profiling with VisualVM part 2'. Once you turned it on, profile your application, take snapshot of profiling results. In the snapshot right-click on the particular class and invoke 'Show allocation stacktraces'.

like image 70
Tomas Hurka Avatar answered Sep 28 '22 18:09

Tomas Hurka