Now that is not something I tried:

  rb_set_end_proc

Thank you very much for this tip. I will try this out too.

What I tried which did not work for me was:

  ruby_vm_at_exit

I read some threads on related topics, and those threads referred to
the ruby_vm_at_exit function, but I found that when I traced all calls
into my code, that this is called after the finalizers have finished
dumping the object table - effectively useless.

I am actually coming up with a new GC integration mini-framework (real
mini, perhaps 100 lines at most) which I will share on Github, which
will handle all basic cases for graphs in C. I think I have convinced
myself that a fundamental bifurcation between GC managed objects
(structs) and managed resources (other structs) has to occur in order to
keep this clean. The former manages the lifecycle of Data_Wrap_Struct
objects, and only incr/decr reference counts on other, internal, C
structs, and only depending upon the specified release-policy, will
recursively release all internal resources. This would allow for
optional user-directed closing of parent resources, which otherwise
would cause a SEGV when child resources are closed. I will share the
link when I have it wrapped up.

The immediate application for me is for Ruby DBI-like drivers for NuoDB,
a new RDBMS, going GA real soon.

Takehiro, thank you for your tip.

Takehiro Kubo wrote in post #1086244:
> On Sat, Nov 24, 2012 at 10:44 PM, Robert Buck <lists / ruby-forum.com>
> wrote:
>> Would someone have an idea of how to approach this, what could possibly
>> be going on? I have been at this for three days now and I don't see any
>> bug on my part.
>
> I had a similar problem. I fixed it by preventing deallocation from
> being called at the program termination.
>
> static int in_finalizer = 0;
>
> static void at_exit_func(VALUE val)
> {
>     in_finalizer = 1;
> }
>
> static void cleanup_func(void *ptr)
> {
>     if (in_finalizer) {
>         /* Do nothing.
>          * Resources are freed at the program termination.
>         */
>         return;
>     }
>     ... deallocate ptr ...
> }
>
> ...
>    obj = Data_Wrap_Struct(klass, mark_func, cleanup_func, ptr);
> ...
>
> void
> Init_xxx()
> {
>     rb_set_end_proc(at_exit_func, Qnil);
>     ...
> }

-- 
Posted via http://www.ruby-forum.com/.