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?
Girish K Gupta
SCJP 1.5 - 87%, SCWCD 1.5 - 92%
Joined: Oct 13, 2005
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?
Joined: May 31, 2011
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.
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.