1

i'm getting StackOverflowError to my recursive call:

    Exception in thread "main" java.lang.StackOverflowError
        at Test.trailMngr(Test.java:112)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        ...
    Java Result: 1

Is there a way to fix this without changing the code?

The only way i can think of is making it a non-recursive method.

Everything else in the code is working fine in smaller input sizes-- i'll avoid the change if possible (although i'm not hopeful).

Not well-familiar with how Java behaves on these things.

TIA.

user3880721
  • 613
  • 6
  • 16
  • 3
    Are the recursive calls terminating? You can increase thread stack space size. [See here](http://stackoverflow.com/questions/3700459/how-to-increase-the-java-stack-size) and [other related questions/answers](http://stackoverflow.com/questions/20030120/java-default-stack-size). – Sotirios Delimanolis Sep 16 '14 at 04:12
  • its very difficult to answer your question with the inputs given – Manjunath Sep 16 '14 at 04:14
  • I think your recursive code is not terminating gracefully. But if your sure about the terminating logic, you should consider increasing the stack size by -Xss option. – SamDJava Sep 16 '14 at 04:19
  • @SamDJava i'm running an exponential alg. and I don't think I made a mistake on the logic. – user3880721 Sep 16 '14 at 04:32

1 Answers1

3

Assuming you're not dealing with infinite recursion, you can increase the stack size using the command-line Xss parameter:

java -Xss8m Test

This is the amount of memory allocated for every thread's internal use. Sizes can be specified in bytes (-Xss8), kilobytes (-Xss8k), megabytes (-Xss8m) or gigabytes (-Xss8g). Note that setting this to a high value will obviously increase your memory usage.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156