[Borges-users] memory strikes back!

Слепнев Владимир slepnev_v at rambler.ru
Mon May 10 12:36:08 EDT 2004


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

PS: Oh noooo, I left the thing on for a minute and it ate up all of 
Windows virtual memory! Save me!


More information about the Borges-users mailing list