Topic Page

Memory and garbage collection interview questions and answers.

Memory and garbage collection questions are a classic part of Java interviews because they reveal whether a candidate understands what the JVM is doing underneath everyday code. This page collects the memory topics that are most useful in backend interviews and production troubleshooting conversations.

Why this topic matters in interviews

Interviewers ask memory questions because Java performance problems are often rooted in allocation patterns, object lifetime, reference reachability, and garbage collection behavior. Strong answers explain not only what the heap and stack are, but also how young and old generations differ, what makes an object eligible for collection, and why pauses or memory leaks happen in real systems.

This topic also helps candidates explain broader runtime behavior. Once you understand how memory is managed, it becomes easier to reason about GC pressure, large object churn, cache design, and why seemingly harmless code can hurt latency under load.

Representative memory and garbage collection interview questions

  1. What is the difference between stack and heap memory?
  2. How does garbage collection work in Java?
  3. What are young and old generations?
  4. What are GC roots?
  5. When does an object become eligible for garbage collection?
  6. What is a memory leak in Java?
  7. What is the difference between minor and major GC?
  8. Why can stop-the-world pauses happen?
  9. How do strong, soft, weak, and phantom references differ?
  10. How would you investigate high memory usage or frequent GC pauses?

Related pages