Is there any way I can return from a recursive function just before it is about to overflow?
public static void func() {
// if it is about to overflow
// return
func();
}
public static void main(String[] args) {
func();
}
I have tried Runtime.getRuntime().freeMemory()
but it returns a same int
every time.
I have also tried to calculate freeMemory
by subtracting Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
but that is not working.
Is there any way in Java to do that? Thank you.