From a8a74995bf137adc0babb81f70a4cd86213d7591 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 22 Apr 2011 09:19:32 -0700 Subject: [PATCH] A module to help debug memory leaks in the watcher. --- lib/compass/commands/watch_project.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/compass/commands/watch_project.rb b/lib/compass/commands/watch_project.rb index fea0cfb4..668b6b81 100644 --- a/lib/compass/commands/watch_project.rb +++ b/lib/compass/commands/watch_project.rb @@ -24,12 +24,37 @@ module Compass end end + module MemoryDebugger + 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 @@runs > 2 + if options.fetch(:verbose, true) && !@@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 + puts "#{type}: #{count} instances." + end + end class WatchProject < UpdateProject register :watch attr_accessor :last_update_time, :last_sass_files + include MemoryDebugger + def perform Signal.trap("INT") do puts "" @@ -116,6 +141,7 @@ module Compass begin puts ">>> Change detected to: #{file}" compiler.run + # report_on_instances(Sass::Importers::Base, :verbose => false) rescue StandardError => e ::Compass::Exec::Helpers.report_error(e, options) end