Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

squash the memleak in dev mode finally (fingers crossed, here)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2620 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit e7f61eab56d8a628cc605e5fa1e9055c4df852c7 1 parent d72201e
@jamis jamis authored
View
4 activerecord/lib/active_record/base.rb
@@ -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
View
19 activerecord/test/base_test.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.