Fellow Rubyists/Rubyians/Rubyans,

I have the simple method below for cloning nested arrays, which calls
the "clone" method for every element of the Array.

class Array
	def clone
		klone = []
		v = nil
		self.each { |v| klone.push(v.clone) }
		return klone
	end 
end            

This works very well, but consumes memory like crazy and within 10
minutes my 1GB machine is already swapping (eats about 2MB per
second)!!

Well, I went ahead and coded the above in 'C' using Ruby's
fanstastically simple API. Guess what? Speed-wise was improved by
almost 30-50%!! Memory-consumption remains the same..

I have no idea what is the problem; regular recursion will use heap
memory from stack, which will get popped after the current level is
completed.

Is there any easy way to see why GC is not deallocating all the
objects?
Or maybe there's some references still attached to the objects?  If
so, are there any utilities to find out what are the references, or at
least provide a peek into what are the main culprits which are
consuming the memory (sort of like a memory profiler)?

/squidster