I am currently learning Java and as part of my training, I tried to intentionally cause a stack overflow to see what it would do.
I did some border testing, and interestingly, I found that if I execute the following code, it will sporadically cause an error. Sometimes it will work without any problems.
public class SO { public static void main(String[] args) { ohno(0); } public static void ohno(int a) { System.out.println(a); if (a != 11413) ohno(a+1); } }
My questions are as follows:
- What could lead to the fact that the size of my stack may vary depending on the execution of this very simple example?
- Stack overflows these days due to poor code construction (i.e. infinite recursion, overly large primitives, etc.) or are there real world scripts where the stack is still a technical limitation?
- This may seem obvious, but .. does the physical memory of the system also increase the size of the stack?
user3884215
source share