Michal Suchanek
7/15/2008 2:16:00 PM
On 14/07/2008, Dave Bass <davebass@musician.org> wrote:
> Sebastian Hungerecker wrote:
> > Assuming the object is not referenced in any other way it will be
> > garbage
> > collected.
>
>
> Eventually.
>
> AFAIK there is no way to force the garbage collector to operate; this is
> in common with most other languages that use garbage collection.
> GC.start or GC.enable do not *force* garbage collection to occur.
>
> But I'm by no means an expert, so someone will probably be along in a
> minute to tell you about a gem that does just that... or it's already in
> v1.9... :-)
>
There might be some non-obvious references to objects stored in blocks
or elsewhere. When you write a piece of code (such as a block) and
save it somewhere the variables that were visible while writing the
block have to be kept around.
Also from what I have heard the GC works by scanning the memory
(stack, whatever) for things that *look* like object pointers. So if
you have a number (or substring, or ...) that points to an object when
interpreted as a pointer that object would not be deleted even though
it is really not referenced ...
When I created lots of small strings and stuffed them into numerous
hashes and arrays the objects did not go away as I would expect. I
saved a gigabyte or two of ram by using JRuby then - it required about
half the memory in this case ;-)
Thanks
Michal