5

In Google's C++ test framework, my eyes read:

.. returns from the current function immediately, possibly skipping clean-up code that comes after it, it may cause a space leak.

while my brain expected to see a memory leak.

Is that terminology used in C++? If so, what does it mean (in other words how it's distinguishable from a memory leak)?


In Haskell, a space leak refers to a situation where a program or specific computation uses much more memory than is necessary.

In Java, using the phrase "space leak" doesn't make sense.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • 1
    I am really curious. Can you show us what code causes this issue? – dimo raichev Dec 20 '18 at 07:47
  • I am curious too @dimoraichev, thanks for translating that into an upvote. I updated the question with a targeted link that leads exactly to the section googletest mentions that. It's doesn't really show code, but you I can imagine that it talks about a situation where the code dynamically allocates memory, then the assert fails, *before* the code has a chance to delete that memory. That's a classic scenario of a memory leak. I am wondering now whether my interpretation was correct, or whether the author used the wrong phrase... That's why I asked the question... – gsamaras Dec 20 '18 at 07:52
  • 2
    I suspect "resource leak" is probably the best wording for that paragraph. Skipping cleanup code could result in leaking things other than memory (open file descriptors, HANDLEs, temp files, etc). I don't think they mean anything special with the term "space leak". – Miles Budnek Dec 20 '18 at 07:53
  • That's a good idea @MilesBudnek, possibly eligible for an answer. After discussing it with the community here, maybe we could contribute there too, and make the wording used better. – gsamaras Dec 20 '18 at 07:55
  • With `Java` objects don't give up their memory until **every** reference to them dies. That means it is quite possible to inadvertently end up with unused objects that should have been deleted but weren't taking up space needlessly. – Galik Dec 20 '18 at 07:56
  • Possible duplicate of [What's a space leak?](https://stackoverflow.com/questions/46007746/whats-a-space-leak) – user1810087 Dec 20 '18 at 08:57
  • Isn't that the link I have already provided in my question @user1810087, which is specific to Haskell, whereas my question is about C++? :) – gsamaras Dec 20 '18 at 08:59
  • @gsamaras Yes it is :) . I did not meant to devalue your question, so it is a *possible* duplicate. And as you accepted the answer saying it is the same as in Haskell it is even more a duplicate. So, as a matter of fact... – user1810087 Dec 20 '18 at 09:45
  • Well, I think that @MilesBudnek comment is the answer user1810087, but I cannot mark a comment as the accepted answer. – gsamaras Dec 20 '18 at 10:01

1 Answers1

5

Space leak does not seem specific to a particular language. Wikipedia has this to say about space leak:

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.

This is same as what it means in Haskell as per your cite.

P.W
  • 26,289
  • 6
  • 39
  • 76
  • But the two questions I linked to, show how it can change context between two languages. However, you answer the question about how it's different than a mem leak, +1. – gsamaras Dec 20 '18 at 07:56
  • @gsamaras: Is C++ more similar to Haskell or JAVA with respect to memory management? JAVA has garbage collection. – P.W Dec 20 '18 at 08:01
  • Interesting. I'd never heard this term used in the context of C++, though it does make sense. – Lightness Races in Orbit Dec 20 '18 at 10:57