JavaScript › Memory Management & Garbage Collection

How can a growing array used as a cache with no eviction policy become a memory leak?

Advanced

Answer

If you keep pushing entries into a cache array/object without ever removing old ones, it grows unbounded for the lifetime of the app, retaining every cached value forever even if most are never accessed again — effectively a slow, self-inflicted leak.
const cache = [];
function cacheResult(key, value) {
  cache.push({ key, value }); // never removed -> unbounded growth
}
Real-world example A long-running dashboard app whose memory usage climbs steadily because every API response ever fetched stays cached forever.

Common follow-ups: How would you bound this cache, e.g. with an LRU eviction strategy?