Recursion Depth - Java

Recently, in a programming competition, I made a big mistake by using recursion for solving one of the problems, as it resulted in 'StackOverflow' error and lost the chance to solve the problem for a larger input dataset. I realized it immediately and implemented a normal solution, but there wasn't much time to provide the solution.

In Java, the JVM stores the method information (Variables, Return Address, etc) and its parameters in the Stack. So, when you use Recursion, they are constantly pushed to the stack memory, until the result of that method is returned. Usually, Stack has limited memory and is much less than the Heapsize.

Below is a Java program, from which you can find the 'Recursion Depth' of the JVM that you are using:

The current 'Recursion Depth' for the JVM on my System is: 9372

The 'Recursion Depth' depends on the present state of the Stack Memory usage, on your JVM. So, it might change, everytime you run it.


1) My own post on StackOverflow site: Basic Java Recursion Method


  1. Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's. seo company in chennai

  2. Thank you for sharing such a nice and interesting blog with us. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle. please keep on updates. hope it might be much useful for us. keep on updating...
    seo company in chennai
    Digital Marketing company in chennai


Note: Only a member of this blog may post a comment.