develooper Front page | perl.perl5.porters | Postings from July 2000

[ID 20000728.004] memory leak with threads under perl 5.6.0

From:
Martin Friebe
Date:
July 31, 2000 11:12
Subject:
[ID 20000728.004] memory leak with threads under perl 5.6.0
Message ID:
38958557.302D11DF@friebe.org
This is a bug report for perl from martin@friebe.org,
generated with the help of perlbug 1.26 running under perl 5.006.


-----------------------------------------------------------------
[Please enter your report here]

I know that threads are experimental, but maybe this will help.

When giving an object reference as argument to "new Thread", the object
will not be destroyed before the programm terminates. It will not be
destroyed, even if all references to the object are undefined. (I think
this happens with all kind of references)
This does not happen, if the object is passed to the thread-sub in a
global variable (which is not part of the argument list)
It seems that the reference count is increased during "new Thread" but
never decreased.

in the following example you can see, that the object is not destroyed
before the programm terminates. This also happens, if you join the
threads correctly. But it should be destroyed after $obj=undef. Because
"my $obj=shift;" removes the reference from @_, and so $obj was the last
reference to the object.

Testet with perl 5.6.0 under RedHat linux 6.1, kernel 2.2.12-20 compiled
for i686, single processor PIII.

best regards
Martin Friebe

-----------------------------sample
#!/usr/bin/perl
use strict;
use Thread;

my $t=Thread->new(\&thr,new Dummy);

   print "thread startet at ".time."\n";
   sleep 10;
   print "ending at ".time."\n";
exit 0;

sub thr {
   my $obj=shift;
   print "got obj at ".time."\n";
   sleep 2;
   $obj=undef;
   print "undef at ".time."\n";
}

package Dummy;
use strict;

sub new {
  my $that  = shift;
  my $class = ref( $that) || $that;
  my $self  = {};
  bless $self, $class;
  $self;
}

sub DESTROY {
   my $self=shift;
   print "Destroying at ".time."\n";

}

1;


[Please do not change anything below this line]
-----------------------------------------------------------------

---
This perlbug was built using Perl 5.00503 - Mon Aug 30 23:08:56 EDT 1999

It is being executed now by  Perl 5.006 - Thu Apr 20 21:29:07 GMT 2000.

Site configuration information for perl 5.006:

Configured by root at Thu Apr 20 21:29:07 GMT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:

  Platform:
    osname=linux, osvers=2.2.12-20, archname=i686-linux-thread
    uname='linux mfriebe 2.2.12-20 #5 wed apr 5 21:08:45 gmt 2000 i686
unknown '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=define useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define
    use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release)
    cppflags='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include'
    ccflags ='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lpthread -lc -lposix -lcrypt

    libc=/lib/libc-2.1.2.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'

    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl 5.006:
    /usr/local/lib/perl5/5.6.0/i686-linux-thread
    /usr/local/lib/perl5/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/i686-linux-thread
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl 5.006:
    HOME=/home/mfriebe
    LANG=en
    LANGUAGE (unset)
    LC_ALL=en_US
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/usr/bin:/bin:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.:/home/mfriebe/bin:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.:/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.:/home/mfriebe/bin:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.:/usr/local/apache/bin:/usr/local/jdk1.2.2/bin:.

    PERL_BADLANG (unset)
    SHELL=/bin/bash






nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About