As we all know that all most all recursive functions can be modified to iterative approach. Suppose we take an example of adding two linklists which represent two huge numbers. This question can be solved either by recursion (which uses system stack) or iterative (explicit stack usage) approach.
My doubt here is if i have given jvm heap size as -Xms2048MB -Xmx2048M
then in the recursive approach will it use all the heap memory for system stack? AFAIK if i will use explicit stack then it can consume all these memory. It will great if somebody can also tell me how, when and how much system stack memory is allocated and little bit of workings. Even pointing to some nice tutorials also will be of great help. As far as possible if it can be confined w.r.t. java
world then it’s good. Thanks.
Advertisement
Answer
This is impossible to occur as the stack frame has its own size. This size can be adjusted by the command line parameter -Xss<size>
.
The heap memory is completly separated from this stack memory.
The default stack size depends on the JVM you’re running