Java – Trace allocation of int []
When viewing my remote application in the jvisualvm through JMX, I found that I saw the memory usage when I was idle:
Using heap dump and jvisualvm to analyze it, I can see that a large chunk of memory is located in several large int [] arrays that are not referenced. By comparing heap dumps, I can see that they seem to be occupying memory and being reclaimed regularly by GC
I'd love to keep track of this because it interests me. My own code will never deliberately allocate any int [] array
I do use a lot of libraries like netty, so the culprit may be elsewhere I do have other servers with the same framework combination, but I can't see this sawtooth there
How can I find out who is distributing them?
Solution
Get a heap dump and find out which objects hold them Once you know what objects hold arrays, you should have a simple time to figure out what to assign them
It doesn't answer your question, but my question is:
Why do you care?
You have told the JVM garbage collector (GC) that it can use up to 1GB of memory Java usage is less than 250m
GC tries to understand the time of garbage collection and how it works in garbage collection In the chart, there is no memory requirement The JVM is not close to the 1GB limit you set I see no reason why GC should work very hard I'm not sure why you care
Garbage collector laziness is a good thing The less GC work, the more resources available to your application
Do you attempt to trigger GC through the "execute GC" button of the jvisualvm? This button should trigger the stop world garbage collection operation Try it when the graph is in the middle of one of the jagged slopes – I predict usage will drop to or below the bottom of the jagged slope If so, it proves that the memory saw is just a pile of garbage and GC is doing the right thing
The following is a screenshot of the memory usage of the Java Swing application I use:
Pay attention to the zigzag pattern
You said you were worried about int [] When I start the memory analyzer and let it describe everything, I can see the allocation of int []
Basically all allocations come from objectoutputstream $handletable The growentries method It looks like the allocated thread is rotated to process network messages I suspect it is caused by JMX itself Maybe RMI (do you use RMI?) Or debugger (do you have a debugger connected?)