How to get the amount of garbage already generated at one point in Java code?

0

So folks, I wonder if they have some method or even way of picking up the amount of Garbage generated the current moment of the code. If you do not know but if you know any DOC that I can study to find a shape, thank you.

    
asked by anonymous 20.09.2017 / 23:41

1 answer

0

I'm not sure if you're going to get exactly what you want, but maybe in one of the classes MemoryMXBean or MemoryPoolMXBean .

Instances of these classes can be obtained with the help of class ManagementFactory . example:

MemoryMXBean memory = ManagementFactory.getMemoryMXBean();

If it is to 'monitor' the process, there are the jconsole or jvisualvm commands that come together with the JDK to monitor the virtual machines - they provide various graphics including memory usage. JDK also offers a variety of instruments .

Another possibility is to use the -verbose:gc (and -XX:+PrintGCDetails ) option on the command line. Additionally -Xloggc:filename to write to a file. I used GCViewer to analyze these logs, very interesting (a few years ago).

    
21.09.2017 / 14:28