Why create a CGI object at all? Doesn't HTTP::Server::Simple give that to you when it calls handle_request?
But to answer your question: garbage collection happens, as I understand it, when the last reference to an object disappears. As long as something refers to an object, it sticks around. This can be annoying, for example, when you've got a closure, so be careful. ;-)
Also note that as you use the CGI module, it loads more of itself into memory and compiles more, and then it stays in case it is called a second time. So if each request causes you to call more parts of CGI.pm, that isn't a leak, it's just that you used more code, so more code had to be loaded and compiled. Avoiding using CGI any more than you have to (e.g., using templates for HTML rather than CGI's html code) may be a good idea here for many reasons, including this one.
| [reply] |
I have found that the data hash that is tie()d with <cpan//Tie::Persistent> is using up so much memory when it contains a lot of data. The funny thing is, even if I tie the data to a local hash, the memory is still allocated and not freed again. E. g.:
sub loadData {
my $file = shift;
my %localhash = ();
tie %localhash , 'Tie::Persistent', $file , 'rw';
untie %localhash;
}
Maybe I don't understand how perl counts references, but in my view that %localhash is a goner. | [reply] [d/l] [select] |
$self->[0] = \%h;
from Tie::Persistent that is making a circular reference. And a circular reference would mean that nothing tied to that module ever gets destroyed (prior to global destruction). (Or the module could be squirreling away a reference to your hash or to the 'tie' object in some other spot even without a circular reference.) Next step: Augment your simple example above with code that shows that the destruction isn't happening when it should and report that to the module author.
1 Wild guess, really. I didn't study the code long enough to understand it. I was just scanning for something like the above which your report made me highly suspicious of existing.
| [reply] [d/l] |