Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 1.03 KB

7e2a.md

File metadata and controls

21 lines (14 loc) · 1.03 KB

Back to questions

Solution to 7e2a: Stack overflow

See code at solutions/code/tutorialquestions/question7e2a

Examine class StackOverflow and compare it with your solution.

Running class StackOverflow from the sample solution three times in succession, I get the following output:

Number of recurseive calls to 'overflow' before stack overflow: 7312
Number of recurseive calls to 'overflow' before stack overflow: 7294
Number of recurseive calls to 'overflow' before stack overflow: 7320

This demonstrates that, even on a single platform, the maximum amount of stack space varies between runs of a Java program. This is because of unpredictable, behind-the-scenes execution by the runtime environment, most notably the garbage collector.

The message is that the programmer can make no assumptions about the precise size of the runtime stack. (Though of course, we do make assumptions about the size of the runtime stack all the time: we assume generally that there is plenty of it!)