From: Nobuyoshi Nakada Date: 2008-07-08T17:07:00+09:00 Subject: Re: mysterious memory corruption, very confused Hi, At Tue, 8 Jul 2008 15:02:58 +0900, Jeff Davis wrote in [ruby-talk:307560]: > Also, what *exactly* can I do between: > x = rb_obj_as_string(y) > and a statement that makes "x" safe (e.g. stores a reference in some > other value that's safe from collection)? Basically, "x" is safe as long as it is refered from an automatic variable. But if you only use the internal pointer of it, e.g., RSTRING_PTR and RARRAY_PTR, it may be optimized out by the compiler. You can prevent this with RB_GC_GUARD macro. RB_GC_GUARD(x) = rb_obj_as_string(y); -- Nobu Nakada