"Csaba Henk" <csaba / phony_for_avoiding_spam.org> schrieb im Newsbeitrag
news:slrnd41nbo.hh5.csaba / ms0.math.ucalgary.ca...
> On 2005-03-23, Kirk Haines <wyhaines / gmail.com> wrote:
> > For hard to find leaks, that's helpful.  Also (and it'd slow the
!#$%@!!!
> > out of your program if you do it a lot):
> >
> > count = 0; ObjectSpace.each_object {count += 1}
> >
> > Gives you a count of the current number of objects.  If you do this in
key
> > places (probably don't want to do it out of set_trace_func), it might
help.
>
> Maybe rather just
>
>  count = ObjectSpace.each_object {}

Or a bit more complex

def ostats(last_stat = nil)
  stats = Hash.new(0)
  ObjectSpace.each_object {|o| stats[o.class] += 1}

  stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v|
    printf "%-30s  %10d", k, v
    printf " delta %10d", (v - last_stat[k]) if last_stat
    puts
  end

  stats
end

Then you can place lines like this in your program

stats = nil
....
stats = ostats stats
....
stats = ostats stats

To look at changes between lines.  Of course this method does create some
instances, too - but no instances of your application classes.  You can as
well add filters (by class or by count) etc.

Kind regards

    robert