Results 1 to 7 of 7
Thread: How big is the stack??
- 03-04-2011, 04:22 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
How big is the stack??
I recently wrote a program which overflowed to stack, without an infinite loop or anything error similar to that. I was just putting too much data on the stack. I am not sure exactly how deep in recursion I ever got, but I wouldn't be surprised that in worst-case scenario, I was 1000 layers deep in recursion. I was able to fix this problem, but was wondering how big is the stack that handles method calls. From my googleing there doesn't seem to be a consistent answer nor is there much documentation on it.
Thanks for any help,
Mike
- 03-04-2011, 04:31 AM #2
It most likely depends upon how much memory is available. But why do you care? If you are gettinga StackOverflowException then you must be recursing too deeply. Fix your code.
- 03-04-2011, 04:35 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
I am just curious, my code is fine. So it is relative to your computer's memory?
- 03-04-2011, 04:47 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
chandu
it mostly depends on the space of how much it is allocated so be careful about that
- 03-04-2011, 04:56 AM #5
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
ok, but how much is that? Is it say a percentage of mem available? Is it a fixed number of bytes (i read from one source that is was a fixed 400kb by default, but that seems alittle low)?
If no one knows, that is fine. But i am just curious, so i would appreciate any info that people can pass along.
Thanks,
Mike
- 03-04-2011, 05:56 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
If no one knows, that is fine.
I suspect that if no-one knows that's not ignorance, but just a consequence of the question not having an answer. See the Java VM spec: 3.5.2 Java Virtual Machine Stacks.
- 03-04-2011, 09:04 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
I don't know the default values but you can set the initial stack size with the -Xms flag and the maximum stack size can be set with the -Xmx flag. Type "java -X" for a listing of all those non-standard flags. On an ordinary PC when a StackOverflowError is thrown you can be sure that your recursive method(s) went all the way down.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Stack layout
By blue404 in forum SWT / JFaceReplies: 0Last Post: 03-22-2009, 02:15 PM -
Help on Stack Implementation
By danver_2009 in forum New To JavaReplies: 1Last Post: 02-16-2009, 09:12 AM -
Stack problem..pls help
By Mika in forum New To JavaReplies: 1Last Post: 02-16-2009, 09:10 AM -
Stack not popping
By bugger in forum New To JavaReplies: 2Last Post: 01-28-2008, 05:59 PM
Bookmarks