RE: memory leaking with closures

2001-09-07 Thread Arthur Bergman



 On Fri, Sep 07, 2001 at 12:27:58AM -0700, Alex Krohn wrote:
  while (1) {
  {
  my $var = 'x' x 50;
  my $sub = sub { my $sub2 = sub { $var; } };
  }
  # $var and $sub should be gone, but memory is never freed
  sleep 1; # Don't crash things =)
  }
  
  will grow forever
 
  it does not grow, definately something strange going on. Happens on
  perl 5.004_04, 5.005_03 and 5.6.1. 
 
 confirmed in bleadperl (patch 11936).  CCing p5p.
 
 atleast one sub { sub{} } leak was fixed recently, but not this one.
 
 - Barrie

Seems like we are not properly freeing the prototype CV which is cloned.

Arthur




SV: memory leaking with closures

2001-09-07 Thread Arthur Bergman


 On Fri, 07 Sep 2001 18:06:17 +0200, Arthur Bergman wrote:
  On Fri, Sep 07, 2001 at 12:27:58AM -0700, Alex Krohn wrote:
   while (1) {
   {
   my $var = 'x' x 50;
   my $sub = sub { my $sub2 = sub { $var; } };
   }
   # $var and $sub should be gone, but memory is never freed
   sleep 1; # Don't crash things =)
   }
   
   will grow forever
  
   it does not grow, definately something strange going on. Happens on
   perl 5.004_04, 5.005_03 and 5.6.1. 
  
  confirmed in bleadperl (patch 11936).  CCing p5p.
  
  atleast one sub { sub{} } leak was fixed recently, but not this one.
  
  - Barrie
 
 Seems like we are not properly freeing the prototype CV which is cloned.
 
 Not likely, since there are always a fixed number of closure prototypes
 when there is no eval to create new ones.

Silly me.

 It is more likely that the reference loop between the inner and outer
 CVs is preventing the freeing of either of them.  I'm not in fact sure
 that the reference loop *can* be eliminated trivially, given these two
 CVs can have different lifetimes.  Perhaps the right solution is to
 move to using weakrefs for CvOUTSIDE(), I dunno.
 

Sounds like an idea anyway. I will give it a try. Only problem I see it will be messed 
up after perl_clone.


Arthur