-2

Because I was having problems with stack overflowing due too deep recursion, I've tried playing around it using while loop. but even tho exiting the recursion before the overflow and re-entering the recursion still causes overflow, how do I clear the allocated memory of the stack that contains the recursion after I exit it?

Caspian
  • 1
  • 1

2 Answers2

0

I'm not sure about that .. but you can try - System.runFinalization(); OR System.runFinalizersOnExit();

  • or Runtime.runFinalizersOnExit(); But I know that these methods have problems (deprecated) .. Check through the Oracle site –  Apr 28 '17 at 15:25
  • I doubt this properly answers his queation, given how unclear the question is. You should wait for clarification before answering. – Carcigenicate Apr 28 '17 at 15:26
  • Thanks for the advice. I'm new here and I do not know the rules so well. –  Apr 28 '17 at 15:41
  • Once you get enough rep, use comments to ask for clarification if the question isn't entirely clear, then answer once you have a better idea about what's being asked. And welcome to the site! – Carcigenicate Apr 28 '17 at 15:49
  • alright I figured out my problem was , I was creating new objects inside the recursion that caused the over flow even tho the recursion was ended. – Caspian Apr 28 '17 at 16:45
0

When your application close the stack should be cleared your recursion is still probably going too deep. Check your code carefully when you are using recursivity make sure your recursive method end. If your recursive method does end, you could increase your stack size but I would not recommend this. Instead, you should ask your self if your method.

but if you want to increase the stack size check this link: How to increase the Java stack size?

Community
  • 1
  • 1
lenon bob
  • 25
  • 8
  • alright I figured out my problem was , I was creating new objects inside the recursion that caused the over flow even tho the recursion was ended. – Caspian Apr 28 '17 at 16:44