From: Asher Date: 2010-08-27T01:51:31+09:00 Subject: [ruby-core:31862] 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? 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? If what I am seeing is the case (and I assume it cannot be and that I am missing something) then the object would never be garbage collected. So how does GC actually occur? What causes the pointer to be deallocated? Asher On Aug 26, 2010, at 12:32 PM, Roger Pack wrote: > It walks the stack, and (for sake of ease of understanding) marks all > pointers still on the stack as "live" > then it marks all of their children as "live" > then all of their grandchildren, etc. > > Then it traverses the entire heap, looking for objects that haven't > been marked as live, and "frees" them. > > NB that these two stages are separate, so they don't conflict. > HTH. > -r