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