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

[ID 20000728.004] memory leak with threads under perl 5.6.0

Martin Friebe
July 31, 2000 11:12
[ID 20000728.004] memory leak with threads under perl 5.6.0
Message ID:
This is a bug report for perl from,
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

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;
   print "undef at ".time."\n";

package Dummy;
use strict;

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

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



[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:

    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 '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=define useithreads=undef
    useperlio=undef d_sfio=undef uselargefiles=define
    use64bitint=undef use64bitall=undef uselongdouble=undef
    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
    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',
    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/, 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:

Environment for perl 5.006:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)


    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About