3 ms·
Vectors haven't been used that much this century. What you describe is not a leak. A leak would be when you loose all references to your Vector and memory is n
by sorokod 10y ago
Vectors haven't been used that much this century.
What you describe is not a leak. A leak would be when you loose all references to your Vector and memory is not reclaimed by the GC.
- joncrocks 10y agoIt's important to note that in Java you don't have leaks in the same way that you do in C. When someone refers to Java 'leaks', they actually mean "Objects that are kept in memory by references that are never used again, but in theory could be." It's like your code is a hoarder, keeping all those old back-issues of newspapers 'In case I need them again' when in fact they are just taking up space.
- coding123 10y agoYes, it's not a leak but many Java devs are aware of these things and instead of typing out "somewhere in my graph I've retained a reference to something that shouldn't" has been colloquially shortened to "GC Leak" and if you see those two words together, they know what it really means.
- the_af 10y agoI'd say even in Java, infinitely adding elements to a collection is not a memory leak, but merely forgetting that memory is finite. No Java programmer I know would call it a memory leak. A leak is when you think you no longer hold references to an object, but you still do, and therefore the GC cannot free its memory. An example is the accepted answer in the StackOverflow link.
- rbanffy 10y agoThe answer in SO is just a more elaborate instance of this same thing: allocating stuff and forgetting to delete all references to it.
- daemin 10y agoI'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.