Module: Compass::Commands::MemoryDebugger

Included in:
WatchProject
Defined in:
lib/compass/commands/watch_project.rb

Instance Method Summary collapse

Instance Method Details

#report_on_instances(type, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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