MediumExperience level: 3-5 years · 8-15 years1 min read

How do you enable and read GC logs to diagnose a memory problem?

Reviewed by Gurusankar M.

Asked inAmazonDeloitteGoogle
#gc logs#unified logging#xlog#pause time#allocation
Report issue

Short Answer

Enable unified logging: -Xlog:gc*:file=gc.log:time,uptime,level,tags (Java 9+). Look at pause durations, frequency, before/after heap per collection, and whether Old gen shrinks after a Full GC. Old gen that stays high post-Full-GC means a leak; long/frequent pauses mean tuning.

On this page

Concept Made Simple

Coffee Chat Question

“How do you enable and read GC logs to diagnose a memory problem?”

Remember It Faster

Mind Map Answer

Enable
-Xlog:gc* (Java 9+) / -XX:+PrintGCDetails (8)
Pause
duration + frequency = latency impact
Heap after Full GC
stays high → leak
Reclaimed
little freed → thrashing

Learn by Doing

Hands-on Keyboard

bash
-Xlog:gc*,gc+heap=info:file=/logs/gc.log:utctime,level,tags:filecount=5,filesize=20m
# analyze in GCeasy.io / GCViewer

Think Beyond the Expected

What If?

After a Full GC, used Old gen barely drops each time — what does that indicate?

A memory leak: live (reachable) objects keep accumulating in Old gen, so Full GC can't reclaim them. The growing post-GC baseline is the signature. Next step: heap dump + MAT to find the retaining GC root.

Real World

GC logs (free, low-overhead) are the first artifact to enable in prod. Tools like GCeasy/GCViewer turn them into pause and throughput charts that immediately reveal leaks vs tuning issues.

Interviewer's Expectation

Keywords they're listening for:

  • -Xlog:gc* unified logging
  • pause time + frequency
  • post-Full-GC baseline = leak
  • low reclaim = thrash
  • GC analysis tools

Common Mistakes

  • Running prod without GC logging
  • Looking only at pause time, not the heap-after-GC trend
  • Using old -XX:+PrintGC flags on Java 9+

Best Practices

  • Always enable rotating GC logs in prod
  • Track post-GC Old-gen occupancy as a leak signal
  • Use GCeasy/GCViewer for analysis

Follow-up Questions

  1. What changed about GC logging flags in Java 9?
  2. How do you tell a leak from under-sizing in the logs?
  3. How does JFR complement GC logs?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Troubleshooting (JVM)
Interview question: "How do you enable and read GC logs to diagnose a memory problem?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.