From: Julian Snitow Date: 2003-03-27T18:12:43+09:00 Subject: [Q] Caveats of rb_global_variable() ? Fellow Rubygoers, For a program I'm working on, I wrote a nifty little class in C (said class being a sort of specialized pseudo-Array for a very performance-sensitive loop), and all is well and wonderful, and the class does everything I'd hoped (and IMO ruby is wonderful to work with even on the C side of things...), but there are two places where I need to protect certain values from the Garbage Collector. In the first case, I just made the value in question into an instance variable, since there's just one such value. In the second case (method StatArray#[]= ), I use rb_global_variable( data_pointer + index ) to protect the stored VALUE from being culled by the GC. It works, but is this a healthy practice? I.e., am I keeping these values from being deallocated until the program terminates, and if so, is there a better way to ensure that the GC does not cull these referenced objects while the StatArray instance exists, but to allow normal garbage collection afterwards? TIA, Julian