MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 1 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.

β˜•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

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

⌨️Hands-on Keyboard

Learn by Doing

bash
-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:

βœ“ -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

  • 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

-Xlog:gcGCeasyGCViewerJFR

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?

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.

Related Questions