| Author |
StackOverFlow error not due to deep recursion
|
Girish K Gupta
Greenhorn
Joined: Mar 14, 2007
Posts: 19
|
|
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
|
Girish K Gupta
SCJP 1.5 - 87%, SCWCD 1.5 - 92%
India
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
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
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
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
Joined: Mar 14, 2007
Posts: 19
|
|
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
|
 |
 |
|
|
subject: StackOverFlow error not due to deep recursion
|
|
|