What objects are garbage collected?

There is a lot of garbage in my application and I would like to analyze this. I want to see which objects are garbage collected. I think this will give me an idea of ​​where to look for optimizations (adding cache or whatever).

Is it possible to print detailed GC information, including how many objects from each class were garbage collected?

I use G1GC if it matters.

Thank!

+3


source to share


5 answers


Oracle JFR (Java Flight Recorder or Java Mission Control) is a great tool to help with this task - it shows the GC load on an object - the value of the number of objects from each class (this along with the collected objects). Highly recommended.



+1


source


That was the answer: How to print java class garbage collection events?

You need to start JVM with arguments



-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails

      

+1


source


I'm not sure about G1GC, but I've generally found the VisualVM toolkit quite useful. It's a decent combination of good feature, adequate deep object analysis, and good speed (a lot of early GC tools suck at this). This is a free tool.

http://visualvm.java.net/download.html

0


source


To monitor the activity of the garbage collection, use the following command:

-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails

      

0


source


I would approach a little differently - you don't need to know which objects are being collected, but which objects are taking up the heap (but were collected after the next GC).

There are several tools that allow you to inspect objects and classes included in the heap, VisualVM as mentioned above, Alex Suo, JProfiler (which is nice but paid for the app), YourKit (the same), or jmap. Using either of these, I could log the state of the heap at regular intervals so you can cross-reference your verbose garbage collection logs.

Depending on your application, you can also make significant progress by using your verbose garbage collection logs in conjunction with your application activity logs (which activities cause noticeable jumps in the heap, especially where there is some similar drop when GC occurs later). Even if you use the tools above, activity logs can be critical in determining where memory usage is coming from.

0


source







All Articles