(fwd) [Borges-users] memory strikes back!

Can anyone of the Ruby experts tell us where the memory leak might be?

···

— forwarded message —

Hi,

about the ol’ Borges memory problem: there’s a small but nonzero
possibility that continuations+objects+weakrefs are a bad combination
in Ruby, after all. Here’s a small test I just wrote. I let it grow to
about 70 megs on my system before shutting it down… although it’s
obvious from the code that memory should be bounded.

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)}

Funny thing is: if we remove the weakref array thing, memory is
bounded; and if we don’t save the continuation, memory is bounded too.
Maybe I’m mistaken somewhere. Actually I hope I’m mistaken. Somebody
correct me.

Vladimir Slepnev

Hi,

···

In message “(fwd) [Borges-users] memory strikes back!” on 04/05/11, Michael Neumann mneumann@ntecs.de writes:

Can anyone of the Ruby experts tell us where the memory leak might be?

Ruby uses conservative garbage collection, which scans C stack and
considers the value suspicious to be a pointer as a pointer. In this
case, perhaps, some unused junk saved in the stack copy in the
continuation object refers to the object, which is a target of a
weakref. I will try something, but it’s hard to promise to fix.

						matz.