From: Tim Pease Date: 2008-07-08T02:14:45+09:00 Subject: Re: mysterious memory corruption, very confused On Jul 7, 2008, at 10:48 AM, Joel VanderWerf wrote: > Tim Pease wrote: >> On Jul 6, 2008, at 7:15 PM, Nobuyoshi Nakada wrote: > ... >>> VALUE x, array; >>> char **foo = malloc(buncha char *); >>> >>> for (big list of things) { >>> x = rb_obj_as_string(y); >>> rb_ary_push(array, x); >>> foo[i] = GetStringValue(x); >>> } >>> >>> By keeping the values in an automatic variable `array', they >>> are marked and won't be freed. >>> >> I am wondering why the strings (returned from rb_obj_as_string) >> will be garbage collected but the array will not be garbage >> collected? Both have the same local scope, and they are not >> referenced by any other ruby object. > > IIUC, 'VALUE array' is a local, hence on stack, hence GC marks it. > The 'VALUE x' local only protects the current string. > Thanks, Joel! That makes sense. Blessings, TwP