From: Roger Pack Date: 2010-08-27T03:36:31+09:00 Subject: [ruby-core:31864] Re: Garbage Collection Question > Right - so how does a pointer ever get off the stack? > > For instance, in my example, where the variable with reference to the object has been assigned nil - the same thing occurs if the variable goes out of scope. > > So in both of those cases, the object "should" be garbage collected; I understand that it's possible, due to conservative GC, that it might mistake a number on the stack (a long), etc. as a valid pointer, but generally when GC runs it should decide that the var (which has no valid ruby references) is no longer live and should be GC'd. Or am I missing something? That's right. > So we have a var with no references in Ruby that is being marked as live by the GC because the pointer has not yet been deallocated. So how does it ever get deallocated in order to not be marked as live? Presumably it is "not being collected" because of a false positive on the stack. So if you go "up and down" long enough on the stack, it will overwrite the false positive eventually (it's hoped), and thus clear the false positive.