I have a function that is called recursively, how to avoid memory overflow ??
int cont = 0;
public void recur() {
recur();
cont ++;
System.out.println("Chamado: " + cont);
}
I have a function that is called recursively, how to avoid memory overflow ??
int cont = 0;
public void recur() {
recur();
cont ++;
System.out.println("Chamado: " + cont);
}
You will need to add an exit clause. For example checking if count == 10,000.
Another option that can happen naturally is that the memory of the machine will end, or if it has a lot of memory, the count value may be greater than the maximum Integer value. [Integer.MAX_VALUE]
You need an exit criterion for recursion.