wilsond has asked for the wisdom of the Perl Monks concerning the following question:
EDIT: Win32::Exe seems to leak terribly. But even more important is that I was using it to get the version info of many Windows EXE files, which is not really what Win32::Exe is for. If you want to do such a thing, use Win32::File::VersionInfo instead as it's waaay faster and doesn't have the leak problem.
Everytime it runs, the count goes up by quite a lot. Memory usage goes up drastically. It ends up using 622MB when it finishes the ten loops.
When I remove the Win32::Exe parts, it doesn't have this problem at all. It seems using undef($exe) doesn't do the trick.
Does anyone have any ideas on what to do about this? This is running in a script (that does many things, including this) that stays running as a Windows service as long as the box is running. This kind of memory usage is unacceptable.
If anyone knows a good replacement for Win32::Exe that does the same thing, I'm highly interested.
EDIT: I found Win32::File::VersionInfo and it seems to do the trick... and faster.
Here's my code:
use Win32::Process; use Win32::Process::Info; use Win32::Exe; use Devel::Leak; sub cmd_processes { my $pi = Win32::Process::Info->new(undef, 'NT'); my $response = { action => 'processes', }; for($pi->ListPids) { my ($info) = $pi->GetProcInfo($_); next unless ($info && defined($info->{ProcessId})); if ($info->{ExecutablePath}) { my $sigalrm = $SIG{ALRM}; eval { $SIG{ALRM} = sub { die "cmd_processes item exe timeout\n"; }; alarm(1); my $exe = Win32::Exe->new($info->{ExecutablePath}); alarm(0); foreach my $var (qw/CompanyName FileDescription FileVersion In +ternalName LegalCopyright LegalTrademarks OriginalFilename ProductNam +e ProductVersion/) { $info->{$var} = $exe->version_info->get($var); } undef($exe); }; $SIG{ALRM} = $sigalrm; } push(@{$response->{process}}, $info); undef($info); } undef($response); undef($input); } for (1..10) { my $handle; my $count = Devel::Leak::NoteSV($handle); print "\nPRE: $count\n"; cmd_processes(); $count = Devel::Leak::NoteSV($handle); print "POST: $count\n"; }
|
---|