LWPng object desctruction and memory usage
Blair Zajac (bzajac@geostaff.com)
Mon, 05 Jul 1999 13:59:51 -0700
This is a multi-part message in MIME format.
--------------9538D2A2D3A307BA7ED51171
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello Gisle,
Its been a while since I've seen any development on LWPng,
but I wanted to point out something that should go into
the next version LWPng's documentation and something
we may want to think about.
Without explicitly deleting some elements of the HTTP::Request
object, the objects will not be destructed until program
completion time. For example, in the News file, you
show the following code
my $res;
my $req = LWP::Request->new(GET => $url);
$req->{'done_cb'} = sub { $res = shift; }
$ua->spool($req);
mainloop->one_event until $res;
if ($res->is_success) {
#...
}
I would place a delete $req->{'done_cb'} or else $req
will not be DESTROYed until the program completes. If
the user also used a data_cb method, then this should
also be deleted.
Also, the following code using the latest Perl and all
necessary packages shows a large amount of memory being
used and not returned. The ps command shows the amount
of memory used by the process under Solaris:
On my system reading a 2 Mbyte file, it returns the
following numbers:
perl 2 MB
perl 5 MB
perl 8 MB
perl 10 MB
perl 12 MB
perl 14 MB
perl 14 MB
It appears that some memory being allocated for storing
the file is not being released. Any ideas?
Blair
use strict;
use LWP::MainLoop qw(mainloop);
use LWP::Request;
&_checkMemory;
my $ua = LWP::UA->new;
for (my $i=0; $i<5; ++$i) {
my $res;
my $req = LWP::Request->new(GET => 'file:/home/bzajac/netcache_config');
$req->{'done_cb'} = sub { $res = shift; };
$ua->spool($req);
mainloop->one_event until $res;
delete $req->{'done_cb'};
&_checkMemory;
}
&_checkMemory;
exit;
sub _checkMemory {
my $psline = `ps -el -o pid,user,vsz,comm | grep $$ | grep perl`;
my @ps = split ' ', $psline;
my $psinMB = int($ps[2]/1024);
print "$ps[3] $psinMB MB\n";
return 1;
}
--------------9538D2A2D3A307BA7ED51171
Content-Type: text/x-vcard; charset=us-ascii;
name="bzajac.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Blair Zajac
Content-Disposition: attachment;
filename="bzajac.vcf"
begin:vcard
n:Zajac;Blair
tel;fax:310-827-8177
tel;work:310-827-3700 x1703
x-mozilla-html:FALSE
url:www.geocities.com
org:Yahoo!/GeoCities
adr:;;4499 Glencoe Avenue;Marina del Rey;CA;90292;
version:2.1
email;internet:bzajac@geostaff.com
title:Technical Yahoo!
x-mozilla-cpt:;32736
fn:Dr. Blair Zajac
end:vcard
--------------9538D2A2D3A307BA7ED51171--