On Sun, 27 Aug 2006, Jez Stephens wrote:

> Hi,
>
> I want to be able to keep track of all instances of a class using
> something simple like this:
>
> Class Thing
>    @@allthings = []
>
>    def initialize
>        @@allthings.push self
>    end
> end
>
> However an obvious drawback to this approach is that instances of this
> class will never be garbage collected due to the reference held in
> @@allthings.
>
> Is there a way to make it so this reference in @@allthings "doesn't
> count", so to speak?
>
> Or is there a better way of doing it?
>
> Thanks for your help

require 'weakref'

check out the docs.

-a
-- 
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dalai lama