swig/Examples/test-suite/ruby/swig_gc.rb
Gonzalo Garramuno 522403958e Added new tests.
Updated swig_gc interface to make it simpler.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9696 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-04-28 17:45:32 +00:00

35 lines
768 B
Ruby
Executable file

#!/usr/bin/env ruby
#
# Put script description here.
#
# Author::
# Copyright::
# License:: Ruby
#
#
# VERY nice function from Robert Klemme to check memory leaks
# and check on what GC has collected since last call.
#
module GC
@@last_stat = nil
def self.stats(klass = nil)
stats = Hash.new(0)
ObjectSpace.each_object {|o| stats[o.class] += 1}
if klass
v = stats[klass]
printf "%-30s %10d", klass.to_s, v
printf " | delta %10d", (v - @@last_stat[klass]) if @@last_stat
puts
else
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
end
@@last_stat = stats
end
end