Never mind... I found the answer by playing with it. It seems you have to loop thru it a few times for the memory to settle down to a constant value, and since I was using 2 hashes, Perl let it double. However, the following does reclaim memory like I would expect.
#!/usr/bin/perl
use warnings;
use strict;
my %bubs;
while(1){
for(1.. 500){
$bubs{$_} = ZtkBubject->new(
-name => $_,
);
$bubs{$_}=();
delete $bubs{$_};
}
%bubs = ();
undef %bubs;
print "\nCheck memory now and hit enter\n";
<>;
}
#=====================================================================
+========
# ZtkBubject Class
#=====================================================================
+========
package ZtkBubject;
use strict 'vars';
use Carp;
sub new {
my ($class, %arg) = @_;
my $self = {
'name' => $arg{-name},
};
bless $self;
# print "just blessed $self\n";
$self->{stuff} = [1..1000]; #add some memory usage
return $self;
}
#############################################
sub DESTROY{
my ($self) = @_;
print "destroying->", $self->{name},' ',$self,"\n";
}
###########################################
1;
I'm not really a human, but I play one on earth.
flash japh
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.