← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Amazon SWE interview with a JVM internals question that honestly felt a bit niche for the round.

Questions Asked (1)

Q1

What happens to a static field of a class when the JVM Garbage Collector runs?

Technical Trade-offsSystem Design
Author's notes

Tripped me up a little because static fields are tied to the class object itself, not to any instance.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that static fields belong to the Class object, which is strongly referenced by its ClassLoader, so they are effectively GC roots as long as the class is loaded. Explain that static fields are not garbage collected while the class is reachable, but they can become eligible for collection if the classloader itself becomes unreachable. Emphasize that the field's value (if an object) can be collected if no other references exist, but the static field itself persists as long as the class is loaded.

Pro tip: Mention that in application servers or OSGi environments, classloader leaks are a common cause of OutOfMemoryError: Metaspace, and that static fields can inadvertently pin classloaders. This shows awareness of real-world JVM behavior beyond textbook definitions.

1. Define static fields and their lifecycle

Explain that static fields are associated with the Class object, not instances, and live as long as the class is loaded by a classloader.

2. Explain GC roots and reachability

Describe how the Class object is strongly referenced by its ClassLoader, which is a GC root, making static fields reachable and thus not collectable under normal circumstances.

3. Clarify what can be collected

Distinguish between the static field itself (never collected while class is loaded) and the object it references (can be collected if no other strong references exist).

4. Discuss class unloading and edge cases

Explain that if the classloader becomes unreachable, the entire class, including its static fields, can be garbage collected. Mention scenarios like dynamic class loading, application servers, and OSGi.

5. Summarize with practical implications

Conclude that static fields are not collected during normal GC cycles, but can lead to memory leaks if they hold references to objects that should be collected, especially in long-lived classloaders.

Key Points to Mention

  • Static fields belong to the Class object, which is referenced by its ClassLoader.
  • ClassLoaders are GC roots, so static fields are reachable as long as the classloader is alive.
  • The object referenced by a static field can be garbage collected if no other strong references exist.
  • Class unloading occurs only when the classloader is unreachable, making the entire class and its static fields eligible for GC.
  • In application servers, static fields can cause classloader leaks and OutOfMemoryError: Metaspace.
  • Weak references and proper cleanup can mitigate memory leaks from static fields.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.