From: Paul Brannan Date: 2001-12-28T23:54:45+09:00 Subject: [ruby-talk:29532] Re: GC and values in extensions On Fri, Dec 28, 2001 at 11:32:02PM +0900, ts wrote: > >>>>> "P" == Paul Brannan writes: > > P> I've heard this same response before, but I'm not sure quite what you > P> mean. How does the GC know how long the object "lives"? > > Look at rb_gc() and stack_end Hmm, interesting. So if I do something like this: VALUE foo(VALUE self) { VALUE x = rb_str_new2("foo"); long y = (long)x; /* Assume x and y now have the same bit pattern */ x = Qnil; ... return Qnil; } then the newly allocated string will not be freed until foo returns? Or if I happen to store an integer that happens to look like a pointer to the heap, then it is possible that some object that has no more references may not actually get garbage-collected? So there is no way to depend on objects being garbage-collected, even if there are no more references? This also sounds a little inefficient to me (though it makes things convenient for extension writers). Is it? Paul