Skip to content

Commit

Permalink
squash the memleak in dev mode finally (fingers crossed, here)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2620 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Oct 15, 2005
1 parent d72201e commit e7f61ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -258,6 +258,10 @@ def self.inherited(child) #:nodoc:
end

def self.reset_subclasses
subclasses.each do |klass|
klass.instance_variables.each { |var| klass.send(:remove_instance_variable, var) }
klass.instance_methods(false).each { |m| klass.send :undef_method, m }
end
@@subclasses.clear
end

Expand Down
19 changes: 19 additions & 0 deletions activerecord/test/base_test.rb
Expand Up @@ -1024,6 +1024,25 @@ def test_interpolate_sql
assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo bar} baz') }
end

def test_dev_mode_memory_leak
counts = []
2.times do
require_dependency 'fixtures/company'
Firm.find(:first)
Dependencies.clear
ActiveRecord::Base.reset_subclasses
Dependencies.remove_subclasses_for(ActiveRecord::Base)

GC.start

count = 0
ObjectSpace.each_object(Proc) { count += 1 }
counts << count
end
assert counts.last <= counts.first,
"expected last count (#{counts.last}) to be <= first count (#{counts.first})"
end

private

def assert_readers(model, exceptions)
Expand Down

0 comments on commit e7f61ea

Please sign in to comment.