Java Terminology – Understanding ‘Space Leak’ in Java

garbage-collectionhaskelljavaterminology

I stumbled across some posts on the main stackoverflow community about whether you can have a 'memory leak' in Java and it (maybe unsurprisingly) creates a lot of contentious debate. At some point I had decided that Java applications don't have memory leaks (or have them all the time depending on how you look at it) but rather have 'space leaks'.

I can't recall where I got this term from did a quick search to make sure I hadn't dreamed it up or something and it seems to be used with regard to Haskell and lazy evaluation. Here, I found a concise definition that appears to be authoritative.

A space leak occurs when a computer program uses more memory than
necessary. In contrast to memory leaks, where the leaked memory is
never released, the memory consumed by a space leak is released, but
later than expected.

The concept of a 'memory leak' as I was taught back in the previous century was caused by losing track of memory without deallocating it. It's something you can detect without understanding the program which is why it's the exact condition that a GC uses to know what is garbage. What people refer to as 'memory leaks' in Java seem to me to be more closely aligned with the term 'space leak' because the application is still referencing the offending memory when it really doesn't need to.

I feel like this distinction would help bring some clarity to discussions about managed memory languages but I'm not sure if it's too much of a stretch? Maybe it's too late but I think it would be best to keep the term 'memory leak' specific and not overload it to also apply to something that produces similar results but has different causes.

To clarify, I am not suggesting that leaks don't happen in a managed application. I'm simply pondering about how we talk about them. There are some highly upvoted discussions about memory leaks and Java that contain flame wars with 'fanboy' slurs and such that center around this exact question. Actually given that even my question is misunderstood tells me that this is an issue of terminology.

Best Answer

Does it make sense to use the term “Space Leak” with regard to Java?

Frankly, no.

While the term is well-founded, and it is (or may be) understood by the Haskell community, the distinction between "space leak" and "memory leak" is NOT widely understood by Java developers or the wider software engineering community1.

Therefore, making a distinction between "space leak" and "memory leak" is likely to cause confusion rather than illumination.

As to the question of whether this term "brings clarity" ... IMO, not necessarily:

  1. You can be equally clear without using this "new" terminology. Possibly even more so ... if you set out fully what you are talking about.

  2. Using terminology that people don't understand does not bring clarity.


1 - For instance, I've been programming for 40+ years, and in Java for 15+ years, and I can't ever recall seeing "space leak" used in this way ... until now.