Memory & GC
Reveal answer and reasoning
Define a maximum count or byte budget and an explicit eviction boundary before choosing a different GC mode. Measure incoming allocations, retained entries after an idle interval, and the ownership of entries currently being processed. A cache entry removed from the dictionary can remain live through an active request. Conversely, retaining a key does not necessarily mean retaining every historical value if updates replace references correctly.
Check both paths and the shape of the stored values.
For an interview, explain why the old cache is not searched from scratch in exactly the same way during every minor collection, then explain why bookkeeping must still preserve young targets. A strong answer separates reachability, the current collection set and reclamation timing. Avoid claims that a write barrier makes the reference thread-safe or publishes a compound business invariant: collector bookkeeping and application synchronization solve different problems.
Modify the portable program so previous points to second after the cache update. Predict the changed name without adding a collection. Then clear previous as well and explain which ownership facts can still be observed and which physical-memory claims remain unproven. Add a second cache field and show why clearing only one field does not remove every path.
In the lab, compare Gen 0, Gen 1 and Gen 2 with the same graph. Write down the candidate set before each run. Your final explanation should distinguish an application root, an older remembered source, an ordinary surviving object and an object outside the selected collection. That vocabulary makes later LOH, pinning and diagnostic lessons much easier to reason about.
What a strong answer covers
- A minor collection does not reclaim the whole heap.
- Old-to-young reference writes must remain visible to a young collection.
- Removing one edge does not remove another strong owner.
Common pitfall
Treating an older object outside a minor collection as if it had already been reclaimed, or treating GC bookkeeping as application synchronization.
Follow-up questions
- What changes when the old cache loses its root before a Gen0 collection?
- Does the write barrier also make a compound cache update thread-safe?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.