# New Ticket Created by  Robert Rothenberg 
# Please include the string:  [perl #36391]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=36391 >




When new objects (blessed references) are created inside a loop, they 
are not properly garbage collected.  For N iterations, N-1 SVs are 
leaked, according to Devel::Leak.  Whether it is a while, for or foreach 
loop does't matter:

   foreach (1..10) {
     my $obj = Some::Class->new();
   }

I am using a version of Perl that I compiled from the source using
the (free) Visual C++ 2003.

See the script below:

package Foo;

use strict;
use warnings;

sub new {
   my $self = { };
   bless $self;
}

package main;

use strict;
use warnings;

use Devel::Leak;

my $handle;
my $start = Devel::Leak::NoteSV($handle);

{
   my $count = 10;
   while ($count--) {
     my $node = Foo->new();
     # even when adding '$node = undef' here, there is still a leak
   }

}


my $finish = Devel::Leak::CheckSV($handle);
my $count  = ($finish-$start);

if ($count) {
   print STDERR "\x23 count = $count\n";
}

__END__

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
   Platform:
     osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
     uname=''
     config_args='undef'
     hint=recommended, useposix=true, d_sigaction=undef
     usethreads=define use5005threads=undef useithreads=define 
usemultiplicity=define
     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=undef use64bitall=undef uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT 
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
     optimize='-MD -Zi -DNDEBUG -O1',
     cppflags='-DWIN32'
     ccversion='13.10.3052', gccversion='', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
     d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, 
Off_t='__int64', lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf 
-libpath:"c:\perl5\5.8.7\lib\MSWin32-x86-multi-thread\CORE"  -machine:x86'
     libpth=\lib
     libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib 
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib msvcrt.lib
     perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib 
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib odbc32.lib odbccp32.lib msvcrt.lib
     libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
     gnulibc_version='undef'
   Dynamic Linking:
     dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf 
-libpath:"c:\perl5\5.8.7\lib\MSWin32-x86-multi-thread\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
   Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
                         PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
   Built under MSWin32
   Compiled at Jun  5 2005 22:11:09
   %ENV:
     PERLDB_OPTS="RemotePort=127.0.0.1:2000"
   @INC:
     C:/perl5/5.8.7/lib/MSWin32-x86-multi-thread
     C:/perl5/5.8.7/lib
     C:/perl5/site/5.8.7/lib/MSWin32-x86-multi-thread
     C:/perl5/site/5.8.7/lib
     .

Reply via email to