module Compass::Commands::MemoryDebugger

Public Instance Methods

report_on_instances(type, options = {}) click to toggle source
# File lib/compass/commands/watch_project.rb, line 29
def report_on_instances(type, options = {})
  @@runs ||= 0
  @@runs += 1
  @@object_id_tracker ||= {}
  @@object_id_tracker[type] ||= []
  GC.start
  sleep options.fetch(:gc_pause, 1)
  count = ObjectSpace.each_object(type) do |obj|
    if options.fetch(:verbose, true)
      if @@runs > 2
        if !@@object_id_tracker[type].include?(obj.object_id)
          begin
            puts obj.inspect
          rescue
          end
          puts "#{obj.class.name}:#{obj.object_id}"
        end
      end
      @@object_id_tracker[type] << obj.object_id
    end
  end
  puts "#{type}: #{count} instances."
end