Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: memory leak

by Athanasius (Canon)
on Jul 27, 2013 at 06:52 UTC ( #1046632=note: print w/ replies, xml ) Need Help??

in reply to memory leak

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:

  • You should use warnings.
  • I don’t think undef $i and undef $j are needed at all, but in any case they should be $i = 0 and $j = 0 respectively.
  • Don’t call functions with an initial & unless you have a good reason to turn off prototyping. Just use: my $ackermann = ackermann($i, $j).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Comment on Re: memory leak
Select or Download Code
Replies are listed 'Best First'.
Re^2: memory leak
by Anonymous Monk on Jul 27, 2013 at 07:00 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046632]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-10-07 02:53 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (170 votes), past polls