Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: memory leak

by Athanasius (Chancellor)
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,

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]
[Discipulus]: map of intenet

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2017-11-23 21:12 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (338 votes). Check out past polls.