Java / Java 17 Garbage Collection Interview Questions
What is promotion in the context of generational garbage collection?
Promotion is the act of moving an object out of the young generation into the old generation because it has proven itself long-lived rather than a typical short-lived object.
Concretely, each time an object survives a minor GC it's copied to a survivor space and its age counter increments; once that age reaches -XX:MaxTenuringThreshold (default 15, and often lowered dynamically based on survivor-space occupancy via -XX:TargetSurvivorRatio), or if a survivor space simply doesn't have room to hold it again, the object is promoted directly into the old generation instead.
Promoting too eagerly (premature promotion) bloats the old generation with objects that would have died shortly after anyway, triggering more frequent and expensive old-gen collections - a common symptom of undersized survivor spaces.
More Related questions...