How do you enable and read GC logs to diagnose a memory problem?
⚡ 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.
☕Coffee Chat Question
Concept Made Simple
“How do you enable and read GC logs to diagnose a memory problem?”
🧠Mind Map Answer
Remember It Faster
⌨️Hands-on Keyboard
Learn by Doing
-Xlog:gc*,gc+heap=info:file=/logs/gc.log:utctime,level,tags:filecount=5,filesize=20m
# analyze in GCeasy.io / GCViewer🔥What If?
Think Beyond the Expected
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:
⚠️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
- 1What changed about GC logging flags in Java 9?
- 2How do you tell a leak from under-sizing in the logs?
- 3How does JFR complement GC logs?
🧩Related Technologies
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.
Was this answer helpful?
⭐ Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.