Please forgive the following if answers appear elsewhere but I have
been trawling docs and news group for the last 2 days and I'm totally
confused

I am writing an OpenGL scenegrapher that uses Ruby scripts to create
nodes within the Scenegraph
The scripts are loaded into a stack within my c++ code
I have a c++ class 'GMScript' and have used swig to wrap into ruby
I use a ruby script that inherits this class
i.e.
class Test1 < Gm::GMScript

        def initialize(sg,p1,p2)

                super(sg,p1,p2)

                @object1 = Gm::GMObjectNode.new("object1")
        end
        .
        .
        .
end

in c++ I call at start

        ruby_init();
        ruby_init_loadpath();
        ruby_script("embedded");
        rb_require("gm.so");            - swigged up wrapper lib

then each time a script load is requested i do the following (protect
code removed for clarity)

        rb_load_protect(rb_str_new2("Test1.rb"),Qfalse,&state);

then
        oClass = rb_const_get(rb_cObject, rb_intern("Test1"));
        scriptObject = rb_funcall(oClass, rb_intern("new"), 
                                  3,sgValue,pathName,className);
        Data_Get_Struct(scriptObject,GMScript,scriptPtr);
        scriptPtr->obj = scriptObject;

The problem is that as I load more scripts previous scripts get freed
of by the GC. In addition, the GMObjectNode's created within the
Scripts are also freed. What I want to do is only free off the Script
when the user deletes it
from the script stack and decide at this time if the GMObjectNode
should
also be deleted. I assumed that since the scriptObject is stored
within the C code the GC would not free these off (or is it because
the scriptObject is stored in GMScript superclass itself. I cannot
mark the object since this is under the control of Swig. I have tried

        rb_global_variable(&scriptObject)

but this does not prevent the freeing and in addition crashes the
program with an error:

/home/steve/TEST/GMScript/Menu/News24/Test1.rb:103: [BUG]
rb_gc_mark(): unknown data type 0x28(0xbfffed78) non object

PS In posting this I have just seen a thread detailing
rb_gc_register_address/rb_gc_unregister_address. I have tried this but
it also fails

I am Using :
ruby 1.8.0
Swig 1.3.19
linux 2.4.18-14smp

I'm sure I'm doing something wrong or have missed something but cannot
work out
what Any help gratefully recieved
Cheers
Steve Hart