From: "ara.t.howard" Date: 2007-09-29T03:18:48+09:00 Subject: Re: [ANN] dike-0.0.1 - a memory leak detector On Sep 28, 2007, at 11:44 AM, Joel VanderWerf wrote: > Does this mean you have to make sure your initialize methods super > all the way up to Object? Or does the Class#new catch it anyway > even if you don't? class ::Class Methods = instance_methods.inject(Hash.new){|h, m| h.update m => instance_method(m)} Dike.ignore Methods Methods.each{|k,v| Dike.ignore k, v} verbose = $VERBOSE begin $VERBOSE = nil def new *a, &b object = Methods["new"].bind(self).call *a, &b ensure Dike.mark_birth object, caller rescue nil end def allocate *a, &b object = Methods["allocate"].bind(self).call *a, &b ensure Dike.mark_birth object, caller rescue nil end ensure $VERBOSE = verbose end end class ::Module Methods = instance_methods.inject(Hash.new){|h, m| h.update m => instance_method(m)} Dike.ignore Methods Methods.each{|k,v| Dike.ignore k, v} end .... module Dike class << self Objects = Hash.new def mark_birth object, stacktrace return if Objects[object_id] object_id = Object::Methods["object_id"].bind(object).call Objects[object_id] = stacktrace ObjectSpace.define_finalizer object, &mark_birth_finalizer (object_id) end .... so, basically, i 'super' for you and never mark the birth twice since it can occur in Object.new, Class.allocate, or Class.new. cheers. a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama