From: Harold Hausman Date: 2007-03-31T22:08:48+09:00 Subject: Re: How to crash Ruby by not registering global C variable ? On 3/31/07, 13 wrote: > Hi list, > > On page 284 of Pickaxe, 2nd edition there is a passage: > > > If you create a Ruby object from C and store it in a C global variable without exporting it to Ruby, you must at least tell the garbage collector about it, lest ye be reaped inadvertently. > Your masochistic behavior scares me a little bit ;), but if I understand your intention correctly, you don't *actually* want to call rb_define_variable like you do on line 13... I believe calling that will cause Ruby to reference the string which is typically a good thing, but in this case it's whats causing you to fail to see the fireworks that you seek. Even if Ruby never references your string, and the garbage collector does 'reap you inadvertently' you probably wouldn't see the fireworks until you happened to dereference the 'str' variable later in your C program, and even then only if the memory in question had been filled with something interesting in the mean time. Thats the slippery nature of the descrivbd problem, when you do fall victim to it it might be tough to debug, because all you're going to have is *occasionally* an 'str' variable filled with something strange. Hope that helps, -Harold