On Wed, Mar 28, 2007 at 07:46:43PM +0900, Pratik wrote:
> Thanks for your replies. I've modified the code a little so that my
> string "hello" is not the last statement. And also, it is used in
> "puts". Even when it's out of scope, it's not being free.

Objects are not freed when they go out of scope. Objects are freed when the
garbage collector runs, and notices that no outside references point to
these objects. (This is "mark and sweep garbage collection")

You can force this to happen using GC.start, if you wish to play around with
the internals.

Doing it other ways (e.g. reference counting) is expensive and error-prone.
I have a vague recollection that Python does it this way though.