Tripped me up a little because static fields are tied to the class object itself, not to any instance.
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.
Explain that static fields are associated with the Class object, not instances, and live as long as the class is loaded by a classloader.
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.
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).
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.
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.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.