[英]Is Stack OverFlow Error possible in finite recursion?
I have a recursive method that I am fairly certain is finite. 我有一个相当确定的递归方法。 However, when I run it I receive a stack overflow error. 但是,当我运行它时,我收到一个堆栈溢出错误。 Is there another possible way to get stack overflow that I happen to be doing or what is wrong with the method? 还有另一种可能导致堆栈溢出的方法,或者该方法有什么问题吗?
public static void solve(int row, int column){
if (row<=8){
if (column>8){
solve(row+1, 0);
}
if (row<=8 && column<=8 && (Rows[row][column]==0)){
for (int a = 1; a<=9;a++){
if (check(row, column, a)==false&&Rows[row][column]!=a){
Rows[row][column]=a;
break;
}
}
}
solve(row, column+1);
}
}
Stack size in JVM is limited so it is possible to get StackOverflow with finite recursion or even without any recursion. JVM中的堆栈大小是有限的,因此可以通过有限递归甚至没有递归来获取StackOverflow。
You can increase JVM stack size using -Xss
option: 您可以使用-Xss
选项增加JVM堆栈大小:
java -Xss16M YouMainClass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.