public class TailRecursionTest2 {
public static void main(String[] args) {
TailRecursionTest2 t = new TailRecursionTest2();
t.a(0);
}
public void a(int j) {
System.out.println(j);
j++;
if (j == 10000)
return;
List list = new Array List<Integer>(100000);
}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList. <init> (Unknown Source)
at TailRecursionTest2.a (TailRecursionTest2.java: 17)
at TailRecursionTest2.a (TailRecursionTest2.java: 20)
at TailRecursionTest2.a (TailRecursionTest2.java: 20)
at TailRecursionTest2.a (TailRecursionTest2.java: 20)
at TailRecursionTest2.a (TailRecursionTest2.java: 20)
public class TailRecursionTest2 { public static void main(String[] args) { TailRecursionTest2 t = new
Share
the issue as you can guess is that you got a memory leek because of the heap is full. You could fix it by increasing the Java heap space but the issue is probably related to your code which may not deallocate the variables properly or your recursive function does not have an “exit point” (check the iteration condition)