From: Joey Marino Date: 2008-03-22T11:49:52+09:00 Subject: object destruction ------=_Part_4994_20384481.1206154203245 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I have a list of objects and after each initialization a few methods are called on them. They are inherently different but perform the same tasks on a different set of data. These tasks require ALOT of memory. After the object has performed its tasks on the data, it is no longer needed and can be destroyed. This way, its memory space can be used for the next object. I am having difficulty destroying these objects since there is no destructor capability in ruby that I can find. I have tried using the garbage collector like follows: ------------------------------------------------- include GC GC.enable GC.starto obj = Object1.new obj.method obj.finalize ObjectSpace.garbage_collect obj2 - Object2.new obj2.method obj.finalize ObjectSpace.garbage_collect #################### class Object def initialize ObjectSpace.define_finalizer(self,self.finalize) end def finalize proc{ |id| puts "finalizing #{id}" } end end class Object1 < Object def initialize super @some_attribute = 1 end end class Object2 < Object def initialize super @some_attribute = 2 end end _________________________ I am assuming this does not destroy the objects since there is no output and memory is not released. I am not even getting output of a finalized object at the end of runtime. Am I doing something wrong or just missing out a key concept here? -- Joey Marino ------=_Part_4994_20384481.1206154203245--