"A memory leak is the gradual deterioration of system performance that occurs over time as the result of the fragmentation of a computer's RAM due to poorly designed or programmed applications that fail to free up memory segments when they are no longer needed."
What parts of the above definition do you think doesn't apply?
If you want I can be more specific to Java: "A memory leak is a situation where unused objects occupy unnecessary space in memory. Unused objects are typically removed by the Java Garbage Collector (GC) but in cases where objects are still being referenced, they are not eligible to be removed. As a result, these unused objects are unnecessarily maintained in memory."
You must be registered to see the links
The element is still being both used and referenced. It's not a dead object, nor is it unused. It's not even a memory leak by that definition.
Did you actually read through the blog post that you cited above? It shows three types of memory leaks that can happen in Java:
"1. Through
static fields"
Not the case here.
"2. Unclosed resources"
Specifically referring to file handles and stream objects. Also not the case here. This is a string or map of strings that is continuously growing (and, again,
actively being used by both the UI and game).
"3. Improper
equals() and
hashCode() implementations"
Again, not the case here.
Simply using an object does not a memory leak make. A memory leak is the failure of the programmer or GC to clean up an object after it falls out of use.
Would it be okay to call it a resource leak (maybe a space leak if you want to get really specific)?
Is your issue the usage of the term "memory" or "leak"?
I take issue with "leak," because it's not a leak. Leaks refer to lost resources. If this object fell out of scope it would be released, but, once again, it's actively being used by the application. It's bending the definition of a "memory leak" far more than I'm willing to accept.
It's literally just "wasted resources." I don't know why people feel the need to attach technical terms to it. Sometimes a spade is just a spade.
Think of it this way. If water escapes from a pipe via a crack, puncture, hole, whatever, you'd rightfully call it a leak. If someone leaves the tap on for no reason, you'd say that they were wasting water. Inno is leaving the tap on. It's not that she didn't maintain her plumbing, it's that she left the faucet on for no reason.
Do you think its possible to have a memory leak in a GCed program?
I know it's possible. I gave an example of how you could easily do it in .NET in one of my previous posts. Aside from holding file handles and streams open, in .NET all you need to do is call
Marshal.AllocHGlobal
without a matching
Marshal.FreeHGlobal
. I'm not sure about the specifics behind how Java handles native integration, but I'm sure something similar would be possible there as well.
Basically, any time you're careless with OS resources (whether you're talking about file handles, unmanaged memory for native integration, etc) you can leak memory. This includes interop, as that generally involves passing a chunk of memory to a program that your execution environment has no control over.