Investigating retained memory
medium 6 minA memory leak in a managed service can consist entirely of reachable objects that are no longer useful.
Video lesson · Chapter 1 of 8
A cache that never releases old tenants
Theory
Read or listen first. About 1 min.
What it is
A memory leak in a managed service can consist entirely of reachable objects that are no longer useful. A rising high-water mark alone is ambiguous because workload growth, allocator retention and filesystem cache can all influence RSS. Measure the live set after comparable collections at equal workload and compare the objects retaining it.
Why it exists
A worker caches data per tenant and never evicts inactive entries. Capture two bounded heap summaries under similar load and group by retained size and owner. A rising post-collection floor with a growing key count supports the cache hypothesis. Use expiry or a size bound consistent with correctness and test churn over several collection cycles.
If the live set stays flat, investigate native buffers, allocator retention, mapped files and file cache before calling it a managed-heap leak.
A cache that never releases old tenants
How it works
Step through the idea, or press Play.
Baseline. A stable set of active tenants leaves a flat floor.
Understand it
Worked incident
A cache that never releases old tenants
| Observation | Live heap after collection (MiB) | Interpretation |
|---|---|---|
| Baseline | 95 | A stable set of active tenants leaves a flat floor. |
| Incident | 360 | Old tenant entries survive collection and the floor climbs. |
| After intervention | 102 | Bound cache ownership and verify the post-collection floor across repeated churn. |
Choose the next investigation
Summary
The whole topic in one minute.
A normal allocator rises between collections. Retained old data changes the baseline after cleanup.
If the live set stays flat, investigate native buffers, allocator retention, mapped files and file cache before calling it a managed-heap leak.