4 ms·
I'd argue that a memory leak is when you've allocated memory that you are not using any more but it has not been freed for some reason. If this happens because
by daemin 10y ago
I'd argue that a memory leak is when you've allocated memory that you are not using any more but it has not been freed for some reason. If this happens because the reference has been truly lost, or if there's something else (like a helpful cache) that is keeping it alive, it doesn't matter. It is still leaked and will only be cleaned up when the program exits.
This applies to resources in general, if they are only reclaimed by the OS when the program exits, then it is a leak.
- krapp 10y ago>if they are only reclaimed by the OS when the program exits, then it is a leak. If this is true, then memory leaks have become a paradigm. I've seen it argued that you should never bother freeing memory yourself, and just let the OS take care of it. It always bothered me.
- daemin 10y agoI think the statement refers to when already shutting down the program. In that case you don't need to worry about freeing OS managed resources as the OS will do that for you when your program exits. Which kind of makes sense but it isn't easy to do without some global flag that you can check and a non-normal destruction path for your objects/data.
- sorokod 10y agoA GC is unable to guess that a programmer is not using a given object. To be eligible for GC the object must not be (strongly) referenced - that is it. Different GCs are tuned for different scenarios - typically balancing throughput and latency. I know of no GC that uses a "strategy" of waiting til program exits to reclaim memory.