Skip to main content
Garbage collection · Topic 6 of 6

GC logging

Definition​

GC logging records every collection: when it happened, how long it paused and how much memory was freed. Turn it on in production so that you can answer "was it the garbage collector?" with evidence.

Example code​

Writing a GC log and reading it

# turn on GC logging, with time stamps, into a file
java -Xlog:gc*:file=gc.log:time,uptime,level,tags -jar app.jar

# what to look at in gc.log:
# - pause times (how long the application stopped)
# - how often collections happen
# - heap size after each collection: if it keeps growing, suspect a memory leak

Finished this page? Track your progress (saved only in your browser).