This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

StackOverFlow error not due to deep recursion  RSS feed

 
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
 
Marshal
Posts: 64494
225
  • 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?
 
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
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!