memory leak when using continuations+weakrefs?

From: "=?windows-1251?Q?=D1=EB=E5=EF=ED=E5=E2_=C2=EB=E0=E4=E8=EC=E8=F0?=" <slepnev_v@...>
Date: 2004-05-11 18:28:09 UTC
List: ruby-core #2864
Hello,

the following code eats up more and more memory as it works, pretty 
fast. It shouldn't.


require 'weakref'

class A
   attr_accessor :child

   def foo
     @child = B.new
     @child.call
   end
end

class B
   def call
     callcc do |cc|
       @cont = cc
     end
   end

   def answer(obj)
     @cont.call(obj)
   end
end

def purge(array)
   array.delete_if {|x| not x.weakref_alive?}
end

a = A.new
arr = []
loop { a.foo; arr << WeakRef.new(a.child); purge(arr)}


If we comment out the line @cont = cc, the leak goes away. If we don't 
save weakrefs at all, the leak also goes away. I don't understand it.

This combination (weakrefs + continuations) is not contrived: it is 
used in the Borges web framework, for an important purpose.

Vladimir Slepnev

In This Thread

Prev Next