On Sun, 27 Aug 2006 23:45:34 +0900, 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 > Have a look at weakref.rb. Either use that directly, or copy ideas from weakref.rb to create your own system. --Ken Bloom -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/