Are stack overflow errors considered memory leak errors?

Viewed 956

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.

2 Answers

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.

"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".

Related