[Rubydotnet-developer] Garbage collection - again
Status: Alpha
Brought to you by:
thomas
From: Thomas S. <th...@th...> - 2003-09-11 23:53:13
|
Hi, If you follow the ruby-talk mailing list you may have noticed that I have asked around about garbage collection, because I sometimes get a core dump that seems to be related to garbage collection on either the .net or ruby side. When I pass a ruby object by reference to .net I wrap it up in a .net object that has a constructor and a finalizer that takes care of 'locking' the ruby object so it is not reaped by the ruby gc: public __gc class Object : public DynamicLanguageSupport::IObject { public: explicit Object(VALUE handle) { _handle = ALLOC(VALUE); *_handle = handle; rb_gc_register_address(_handle); } ~Object() { rb_gc_unregister_address(_handle); free(_handle); } // stuff for invoking ruby methods from .net removed private: VALUE __nogc *_handle; }; I just grepped through your code and you don't seem to use the rb_gc_(register|unregister)_address functions. Do you know another trick for keeping the ruby GC from reaping the ruby objects that are only referenced from .net? Btw, I have just thought of something! The .net GC runs asynchronously and the finalizer may just be invoked on a bad time causing everything to bomb because ruby is not thread safe. Cheers, Thomas |