Results 1 to 7 of 7
  1. #1
    mgeno216 is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default 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

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    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.

  3. #3
    mgeno216 is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    I am just curious, my code is fine. So it is relative to your computer's memory?

  4. #4
    chandu_g_g is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default chandu

    it mostly depends on the space of how much it is allocated so be careful about that

  5. #5
    mgeno216 is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    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

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,338
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by mgeno216 View Post
    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
    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Stack layout
    By blue404 in forum SWT / JFace
    Replies: 0
    Last Post: 03-22-2009, 01:15 PM
  2. Help on Stack Implementation
    By danver_2009 in forum New To Java
    Replies: 1
    Last Post: 02-16-2009, 08:12 AM
  3. Stack problem..pls help
    By Mika in forum New To Java
    Replies: 1
    Last Post: 02-16-2009, 08:10 AM
  4. Stack not popping
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •