Chester K has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a server that needs to dynamically load differing pieces of code for different tasks and types of data. The code for any given package is created by compiling legacy BASIC code into perl code (with Parse::RecDescent) in its own namespace based on the source BASIC file. Since I'm dealing with potentially thousands or tens of thousands of namespaces, memory usage would go through the roof if they all remained in memory together (only a handful need to be in memory together at any given time).

In the search for a possible solution to the problem, I came across Symbol::delete_package, which appears to blast the symbol table for a given package clean. My question is this: When I use Symbol::delete_package to destroy a package, I imagine that the memory previously used by the variables in the package is freed for reuse, but does the memory previously held by the code in the package get freed for reuse, or does it simply remove it from the symbol table and continue holding onto the memory?
  • Comment on Does Symbol::delete_package free memory used by subs?

Replies are listed 'Best First'.
(tye)Re: Does Symbol::delete_package free memory used by subs?
by tye (Sage) on Jul 30, 2002 at 05:15 UTC

    There was a bug in Perl that prevented no-longer-used code blocks from being free()d from memory (on most operating systems, this only makes that memory available for reuse by perl). It amounted to circular references in the case of code blocks. I think this was fixed for Perl 5.8.

            - tye (but my friends call me "Tye")
Re: Does Symbol::delete_package free memory used by subs?
by belg4mit (Prior) on Jul 29, 2002 at 23:47 UTC
    It looks like yes, otherwise this would be the same as reset.

    Other points of interest. If the code was stored as a coderef, it would disappear when you cleared the var. If worse came to worse you could fork, block, and do your thing in the child, have the child exit, and the parent continue.