Your test code looks broken: you're only calling two functions in the recurse1() case.
Even after you fix it, it still won't use as much memory as the recursive case. That's the nature of recursion; every time you make another function call, Perl has to save another stack frame. When you return, Perl pops that frame off the stack. (This is a bit over simplified, but think of it like setting aside a task in memory for a moment to do another task. When the second task is done, you return to the first.)
I wouldn't classify this as a memory leak, because it appears that Perl is doing exactly as it should do.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||