Mongers,

I've been trying to track down a memory leak in a long running perl script that 
uses IO::All to write a bunch of files every few seconds.  I traced my leak 
back to IO::All which checks to make sure the version is at least 5.8.0 before 
calling untie.  Pretty innocuous, imho.

Here's an easy way to reproduce it.  In perl 5.10.1, this script causes perl's 
memory to grow really big.  It appears to be fixed in later versions of perl 
because there is no memory leak on my mac (perl 5.18.2).

perl -E 'for $i (0..100_000_000) { 1 if ($^V) }'
and
perl -E '$foo = version->new(v1.2.3); for $i (0..100_000_000) { 1 if ($foo) }'
and (slower)
perl -E 'use IO::All; for $i (0..100_000_000) { "file contents" > 
io("/tmp/filename") }'

Is there a way of fixing my script so I can still use IO::All and not have a 
memory leak?  Here is one way, but I suspect there are better methods that 
won't break with a future version of IO::All.

use IO::All;
{
  no warnings 'redefine';
  sub IO::All::DESTROY {
    my $self = shift;
    no warnings;
    #unless ( $^V and $^V lt v5.8.0 ) {
        untie *$self if tied *$self;
    #}
    $self->close if $self->is_open;
  }
}

Thanks,
Duane



Duane Bronson
[email protected] <mailto:[email protected]>
http://www.nerdlogic.com/ <http://www.nerdlogic.com/>
5 Goden St.
Belmont, MA 02478
617.515.2909





_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to