Hello ch.sarath, and welcome to the Monastery!
It looks as though you are trying to compute a variation of the Ackermann function (note the spelling), which is notable precisely because “Its value grows rapidly, even for small inputs.” Of course you are running out of memory (that’s kind of the point!), but this has nothing to do with a memory leak, and there is no way to “eliminate” this problem when designing recursive functions. Update: Seems I was too hasty here: consider Memoization as a technique for managing these kinds of problems. Thanks to Anonymous Monk, below. Best reference on memoization I know: Chapter 3 of Higher-Order Perl by Mark Jason Dominus.
Some additional notes:
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: memory leak
by Athanasius
in thread memory leak
by ch.sarath
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |