Posted on 2003-10-25
I created my own tree class to generate a game tree for a tictactoe game. The general idea is that the GameTree consisits of a root node which is an object i created called a TreeElement, and an array of GameTree called the children. Later on in the code, I have a recursive method called generateTree which, among other things, determines how many children a GameTree has (based on the current game configuration), and calls generateTree on each of the children. The terminating condition is when the GameTree has no children.
When I first tested my method on a small subtree of the my game tree, it worked fine. Then I tried a bigger subtree, and I got a java.lang.StackOverflowError. The frustrating thing is that after that, I got the same Error when i ran the method on any GameTree, even one with no children (in which case the method was just supposed to return).
The Java APIs says that a StackOverflowError occurs when a method recurses too deeply. So is there a way to increase the maximum depth of a recursion before it returns the Error?
Also, the fact that it still doesn't work for a subtree that it previously worked for seems to imply that there is a problem with memory allocation. System.gc() doesn't seem to work, so do you have any suggestions?