Why do collectors age a survivor through several young collections instead of promoting it the first time it survives?
answer
- one survival can be an accident
- allocated just before the collector arrived
- each survival is another copy
- evidence weighed against copying cost
- an overflow promotes regardless of age
basics
~20 sOne survival is weak evidence of a long life: an object allocated just before a collection survives on timing alone. Requiring several survivals filters those out, so the mature area receives objects that have genuinely proved long-lived rather than unlucky ones.
solid answer
~40 sPromotion is a one-way, expensive decision: once an object is in the mature area, its space can only be recovered by a rare and costly collection. The collector therefore wants evidence, and surviving once is poor evidence — an object allocated a moment before the collector ran is alive purely because of when it was created. Surviving `k` collections means it stayed reachable across `k` intervals, which is much stronger. The cost of that evidence is real: every extra survival copies the object again and needs somewhere to keep it while it ages. So the promotion age balances premature promotion against repeated copying, and any aging area has a limit — when it is full, survivors are promoted regardless of age.
code
pseudocode · 11 lines// called for each live object found during a young-area collection
evacuate(obj):
obj.age = obj.age + 1 // the counter travels with the object
if obj.age >= PROMOTION_AGE:
new = copy_into(mature_area, obj)
else if aging_area_has_room_for(obj):
new = copy_into(aging_area, obj) // will be copied again next time it survives
else:
new = copy_into(mature_area, obj) // overflow: promoted below the age
install_forwarding(obj, new)
return newgo deeper
Remember the idea rather than the mechanics: surviving one collection may just mean an object was created at an awkward moment, so collectors wait for more evidence before moving it.
Explain the counter and the threshold, and that the counter is carried across copies. Be able to say what the collector gains by waiting and what each extra wait costs in copying.
Reason about both failure directions in a live system: a threshold too low fills the mature area with objects about to die, one too high spends the young collection's budget on copying and then overflows anyway.
Treat the age as an estimator threshold fitted to a workload's lifetime distribution, and be clear about its limit: it cannot reduce promotion caused by objects that really are alive when the collector runs.
## One survival proves little A young-area collection takes a snapshot at an arbitrary moment in an object's life. Consider two objects, both of which stay reachable for 50 ms, in an area collected every second: - one is allocated just after a collection and dies long before the next — never seen by the collector at all; - the other is allocated 20 ms before a collection and is still reachable when it runs — a survivor. They have identical lifetimes. The second survived because of **when** it was allocated, not because of what it is. If the collector promoted every survivor, it would promote this object, which dies 30 ms later, into the area where dead objects wait longest to be reclaimed. ## What aging measures Aging attaches a small counter to each object and increments it each time the object is evacuated from the young area as a survivor. Promotion happens when the counter reaches a **promotion age**. The counter is a lifetime estimate expressed in the only currency the collector has: intervals lived through. Surviving `k` collections means an object stayed reachable across `k` fill-ups of the young area, which is far stronger evidence of a long life than surviving one. The counter travels with the object when it is copied; a copy does not reset it. ## The cost of the evidence Aging is not free, and the price is paid by exactly the objects the collector is unsure about: - **Repeated copying.** An object promoted at age `k` is copied `k` times, once per surviving collection. Copy work per collection scales with the volume of survivors, so a high promotion age multiplies the work of every young collection. - **Space to age in.** Survivors that are not yet promoted have to live somewhere outside the area about to be reused. That area is reserved footprint that ordinary allocation cannot use. - **A hard limit.** That aging space is finite. When a collection produces more survivors than it can hold, the excess is promoted immediately, whatever its age — an overflow that silently defeats the filter precisely when survival is highest. ## Choosing the promotion age | promotion age | effect | |---|---| | too low | objects that were about to die reach the mature area; occupancy and mature-collection frequency rise | | too high | survivors are copied over and over, and the aging space overflows, forcing promotion anyway | | well matched | short-lived objects die in the young area; genuinely long-lived ones reach the mature area quickly | The useful framing for an interview is that the age is an estimator threshold. Set it against the shape of the workload's lifetime distribution, not as a constant to be raised whenever promotion looks high. Many runtimes also adapt it at run time from the observed distribution of survivor ages rather than holding a fixed value, and ecosystems differ in how much of that is exposed for an operator to override. ## Where aging cannot help Aging filters objects whose survival was an accident of timing. It does nothing for two other populations: 1. **Genuinely long-lived objects.** A cache entry meant to live for hours will pass any threshold; aging only delays its promotion and adds copies in the meantime. 2. **Objects whose lifetime exceeds the collection interval.** If a unit of work holds its objects longer than the young area takes to fill, every one of those objects survives every collection by construction. Aging then just copies them repeatedly before promoting them anyway, and the real remedy is to lengthen the interval or shorten the hold. That is the honest limit of the mechanism: aging improves the **quality** of the promotion decision, but it cannot lower a promotion rate that is caused by objects genuinely being alive when the collector runs. ## What an interviewer is listening for That you frame promotion as a decision under uncertainty and aging as the evidence-gathering that improves it; that you name the copying and footprint it costs; and that you know an object can be promoted below the age when there is nowhere left to age it.
- What can force a survivor to be promoted before it reaches the promotion age?No room left to age it. The space that holds not-yet-promoted survivors is finite, so a collection that produces more survivors than it can hold promotes the excess immediately, whatever their counters say. This happens exactly when survival is unusually high, which is when the filter was most needed.
- Is setting a very high promotion age a safe default?No. Each extra survival copies the object again, so a high age multiplies the copying done at every young collection and enlarges the space that survivors need. Past a point the aging area overflows and objects are promoted anyway, so the extra copies bought nothing.
saying these in an interview costs you the question
- Thinks every survivor of a young collection should be promoted at once
- Believes copying an object into the aging area resets its age counter
- Assumes a higher promotion age is better on any workload
- Says an object can never be promoted before reaching the promotion age
- Thinks aging is free because survivors are copied anyway