perlfaq nodetype
faq_monk
<P>
You can't. On most operating systems, memory allocated to a program can never be returned to the system. That's why long-running programs sometimes re-exec themselves. Some operating systems (notably, FreeBSD) allegedly reclaim large chunks of memory that is no longer used, but it doesn't appear to happen with Perl (yet). The Mac appears to be the only platform that will reliably (albeit, slowly) return memory to the
<FONT SIZE=-1>OS.</FONT>
<P>
However, judicious use of
<CODE>my()</CODE> on your variables will help make sure that they go out of scope so that Perl can free up their storage for use in other parts of your program.
<FONT SIZE=-1>A</FONT> global variable, of course, never goes out of scope, so you can't get its space automatically reclaimed, although
<CODE>undef()ing</CODE> and/or
<CODE>delete()ing</CODE> it will achieve the same effect. In general, memory allocation and de-allocation isn't something you can or should be worrying about much in Perl, but even this capability (preallocation of data types) is in the works.
<P>