Hello,

I've got a problem with the way ruby handles symbols (e.g. names of instance
variables).
The following ruby program creates an object and an instance variable inside
each object.
Whereas the object will be deleted by the gc when it isn't needed any more,
the name of
the instance variable will remain in the symbol table of ruby, thus creating
memory leaks.

class TestClass
end

1000000.times{ |i|
  command = "@varName#{i} = nil"
  a = TestClass.new
  puts "Evaluating #{command}"
  a.instance_eval(command)
  GC.start	# try to remove old objects
  puts "a.instance_variables = #{a.instance_variables}"
}

Does anyone know how to solve this problem?

Before you ask, why anybody does crazy things like creating instance
variables with instance_eval:
I use ruby as an embedded interpreter inside a test application. The state
of the test is reflected inside
ruby as an object tree. The state of a single object is represented by
instance variables created by rb_iv_set. So the test state can be checked and
altered by ruby scripts.
Stupidly ruby graps all my memory to store symbols and crashes the test.

By the way: I'm interested in gaining experiences about ruby as an embedded
interpreter. So please
drop me a line, if you have made experiences with topics like
multithreading, gc, ruby threads, the way
ruby (mis)uses the stack, ...

Thanks in advance

Dirk


-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte l?cheln! Fotogalerie online mit GMX ohne eigene Homepage!