3 ms·
Pedantic point: a dangling reference is the same thing as a premature free. If we free(p) but then the pointer hangs around in the program and we use it, we hav
by kazinator 7y ago
Pedantic point: a dangling reference is the same thing as a premature free. If we free(p) but then the pointer hangs around in the program and we use it, we have used a dangling pointer.
What this seems to be talking about is "semantic memory leaks": objects that are not reclaimed because they are reachable, and this reachability is unintentional.
For instance, suppose we process a stream of real time data which exhibits locality. Some items appear in it and are likely to appear again, but eventually disappear forever. We can put items into a cache to speed up processing. But if we don't expire the cache, it could grow without bound; the items that will never be seen persist in it, and new items keep being added.
That's a bug in the algorithm, not in the memory management. Memory management has nothing to say here; it has no idea about the parameters that drive the cache size or replacement policy.
Implementing cache expiry in this scenario has little or nothing to do with manual memory management. Manual memory management cannot just blow away any object it feels like based on it age or recency of access.