4 ms·
Holding onto a pointer that should be freed is leaking memory.
by eridius 15y ago
Holding onto a pointer that should be freed is leaking memory.
- ghusbands 15y agoThat is overly conservative. A perfect garbage collector that always runs in reasonable time is provably impossible. What sambeau said is that it often holds on to [an allocation] for too long, which is true to varying extent of all garbage collectors. To leak memory is to fail to deallocate it at all.
- gchpaco 15y ago"Leak" may be the right word for some configurations with conservative GC. A "leak-free" GC would presumably guarantee eventual collection of all dead objects, which is impossible with a conservative GC in theory, and in practice it's not especially difficult to get into a configuration with the Boehm GC where the lifetime of a dead object is infinite (usually because it doesn't move and some binary data that the GC thinks might be a pointer doesn't go away, because it's texture data or something).
- sambeau 15y agoAnd of course there are many valid programs where leaking memory is totally fine (and more performant): shell tools, cgis etc. When I write any of these, the only time I free anything is when I've had to malloc something huge.
- cpeterso 15y agoInterestin dichotomy: In a managed system, a "leak" is when a pointer points to a memory allocation too long. In an unmanaged system, a "leak" is when you have no pointers to a memory allocation. :)