by sorokod · 9y ago · 0 comments
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.
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.
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.
This applies to resources in general, 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.