• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StackOverFlow error not due to deep recursion

 
Girish K Gupta
Greenhorn
Posts: 19
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Has anyone ever encountered a stackOverFlow error which is not caused by deep recursion?
Theoretically it is possible http://en.wikipedia.org/wiki/Stack_overflow because of big local variables.

I tried reproducing by using a very low stack size (using -Xss8k) and then declaring a large number of local variables but I was unsuccessful.



In this program I am declaring 2000 double variables that would take 2000*8 = 16000 bytes of memory (~16k) which is much more than set 8k but still this program runs successfully.

Any pointers/suggestions? Am I doing anything wrong?

Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the maximum heap size rather than stack size. I would not have thought 2000 is a lot; you will probably find there is enough space on the stack for 5000 method calls, which is a lot bigger than 2000.
Are you sure the size you are setting is in kB rather than stack elements?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:you will probably find there is enough space on the stack for 5000 method calls, which is a lot bigger than 2000.

I tried with the sample program showed by Girish, and was able to hit the below error (both in Eclipse and cmd prompt) when there are exactly 5028 double variables declared.

Note that I have specified 1K as the stack size.

 
Girish K Gupta
Greenhorn
Posts: 19
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John

Even I had got that error, though I don't remember how many double variables I had used.

In your code example the memory required to store 5028 doubles is around 40k, much more than the specified 1k. It would take only 128 doubles to fill up this memory. I am unable to understand the behaviour.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic