From: Roger Pack Date: 2007-10-19T03:06:32+09:00 Subject: Re: ruby wish-list GC wish list: Isn't it possible to create your own reference checking style object? Would this be possible, for example. Class Object attr_reader :internal_object # only used if you call new_with_timely_death_wrapper for your new call--see below def new_with_timely_death_wrapper class_to_use, *args @internal_object = class_to_use.new *args # since this object is 'only internal' deleting it later will be OK end def assign_to_me this_wrapped_object dec @internal_object = this_wrapped_object.internal_object inc end def do_method name, *args eval("@internal_object.#{name} *args") # ok there's probably a better way :) maybe object.internal_object.do_whatever args end def dec @internal_object.count -= 1 recycle_current_object if count == 0 end def inc @internal_object.count += 1 end def recycle_current_object # traverse internal members of @internal_object--force_recycle them, unless they're wrappers, then just dec them. @internal_object.recycle end def inc @internal_object.count += 1 end def go_out_of_scope dec self.force_recycle # we are toast :) -- this is scary and might not be right end end Then the example: a = Array.new_with_timely_death_wrapper(0,0) b = Array.new_with_timely_death_wrapper(0,0) # only time you should use assign is on start b.assign_to_me a #recycle's b's object, assigns internal_object to a's internal_object.a, sets count to 2 a.go_out_of_scope # a set to 1 b.go_out_of_scope # a set to 0 -- recycled. ? -- Posted via http://www.ruby-forum.com/.