void function(int x){
if(x<=0)
return;
function(x--);
}
This is a recursion function which is called with the value of x = 20.
The Recursive call will take place in this way
function(20)...function(19).......function(0)
Each function call will use some memory and if the data is big it will throw StackOverflowException.
So what I want to know is:
Is there any way by which we can call a function and remove it from the call stack so that its memory can be utilized (eg. after function(20) calls function(19) the memory for function(20) should be de-allocated), and the the end of the recursive call (here function(0) ) it should get returned from the first place from where it was called (i.e. function(20)).
Can this be done in Java and C?