Hi!
I’m having trouble getting some parts of my C++ bindings to play well
the Ruby Garbage Collector. The problem is that one of my classes, let’s
call it B, depend on having at least one instance of another class, A,
to exist for its constructor and destructor to work properly. This is
not really an issue when initializing instances of class B as I only
need to make sure an instance of A has been created beforehand, but I
can’t figure out how to ensure that the underlying C++ destructor of
class A gets called AFTER all instances of B have been deleted when my
Ruby code terminates.
Using ObjectSpace.finalizer, I could tell that the Ruby wrapper objects
themselves get deleted in reverse order they were created, which is what
I want, but for some reason the underlying C++ objects don’t get deleted
in that order.
Does anyone have any tips on how I should go about to solve this? I’ve
been using SWIG thus far to create bindings to my C++ code and am not
very familiar with the inner workings of the Ruby VM, but am more than
willing to learn it if there’s a solution to be had.
Thanks!