I try to write an exentension module with containing the following
method:
It wraps a c++ and binds it to ruby global variable.

void BindToRubyVariable(someObject* native, char* variableName) {
  VALUE klass = get_ruby_class_object_from_somewhere
  VALUE ruby_obj = Data_Wrap_Struct(klass, 0, 0, native);
  rb_define_variable(variableName, &ruby_obj);
}

I call it like this:

BindToRubyVariable(some_obj1, "foo");
BindToRubyVariable(some_obj2, "bar");

Now the problem is that the first object gets GCed, although it should
still be accessible in ruby via $foo. Or am I totally wrong?
Any ideas why it is like that?
What can one to prevent GC killing my object?

Best regards,
gecki