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"; }

In reply to Win32::Exe causing leaks? by wilsond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.