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

M

Michael Neumann

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
 
Y

Yukihiro Matsumoto

Hi,

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

|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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top