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

I profile my Java application using VisualVM and I went through

profiling_with_visualvm_part_1

profiling_with_visualvm_part_2

When I see the result of a memory profile, I see millions of Objects[] , Char[] , String and other such fundamental objects that occupy all of the memory. I want to know which of my classes (or my code) are actually responsible for creating these Objects[] and String , etc., until I can find it. As soon as I know the class of the offender, I can dive into the code and fix it.

I put the filter com.mypackage.* , But I see that they are all many times smaller (sometimes 0 bytes) compared to the total size of Objects[] , Char[] , String .

I believe there should be a way to find the criminal code. Otherwise, the profiler will not be very useful.

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

+8
java profiling profiler visualvm
source share
1 answer

If you want to see what code allocates these instances, go to "Memory Settings" and turn on "Traces of the record allocation stack." The option "Record stack trace" is explained by "Profiling with VisualVM part 2" . After you enable it, profile the application, take a picture of the profiling results. In the snapshot, right-click on a specific class and call "Show placement stack classes".

+2
source share

All Articles