From: Eric Hodel Date: 2010-05-26T12:03:37+09:00 Subject: Re: The order of garbage collection On May 24, 2010, at 22:55, Ali Polatel wrote: > The problem is when the parent of an object is freed, the object is > freed automatically as well. For example when a Threads object is freed, > all the Thread objects that belong to it are freed automatically. This > means when the Database is freed all, or closed by the user, the > underlying objects are freed automatically by talloc. This means an > object may only be freed if its parent hasn't been freed yet. > > So far so good, to make ruby's gc play nice with this way of allocation, > every struct that represents an object has an element VALUE parent and > it's marked using rb_gc_mark(object->parent) in the mark phase. > > This problem arises when e.g. I have a database and message object and > both of them go out of scope. Ruby-1.8 frees the message first and then > the database but Ruby-1.9 does the opposite thus my extension blows. > > How can I ensure the objects are freed in order, from children to parent? You'll need to impose the order in your free functions. You can't depend on even ruby 1.8 to free the items in the proper order by itself.