7

In Java? Yes or no? Simple question, but I can't find a definitive answer anywhere. Most explanations of memory leaks I read only concern the heap, as if this cannot happen in the stack.

This is not answered by the "Creating a memory leak with Java" stack overflow question because that article makes no mention of whether stack overflow errors are considered a kind of memory leak.

Wes
  • 1,183
  • 3
  • 23
  • 51

2 Answers2

11

A memory leak is a scenario that occurs when objects are no longer being used by the application. I think in the case of a recursive call, the objects are required at a later point. So I would not consider a stack overflow error a memory leak.

Boann
  • 48,794
  • 16
  • 117
  • 146
Shashank
  • 249
  • 2
  • 13
7

"Memory leak", in brief, refers to the scenario that memory is allocated but not released even if it is no longer needed.

A stack overflow itself is NOT causing any unneeded memory to fail to be released. There is no reason that you can treat a stack overflow as a "memory leak".

Boann
  • 48,794
  • 16
  • 117
  • 146
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131