When a variable goes out of scope, does anyone around hear its scream?
This is not a ruby ββquestion, but a general question about garbage collection. In a garbage-collected language like Ruby or C #, when a variable falls out of scope, it is flagged in some way, which means that it is no longer used. When this happens, you can no longer attack him, and he sits around poking his thumbs, but he still has a dedicated memory.
At some point, the garbage collector will wake up and look for variables marked as unused. He will get rid of them, and at this moment they are no longer in memory.
It may be harder than this, depending on how the garbage collector works, but it's close enough :)
source share