Permalink
Browse files

Fixed memory leak with Active Record classes when Dependencies.mechan…

…ism = :load #1704 [c.r.mcgrath@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2276 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8a35865 commit 6a519401176126cd808aa5e3562a21f34a64de65 @dhh dhh committed Sep 20, 2005
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed memory leak with Active Record classes when Dependencies.mechanism = :load #1704 [c.r.mcgrath@gmail.com]
+
* Fixed Inflector.underscore for use with acronyms, so HTML becomes html instead of htm_l #2173 [k@v2studio.com]
* Fixed dependencies related infinite recursion bug when a controller file does not contain a controller class. Closes #1760. [rcolli2@tampabay.rr.com]
View
9 activesupport/lib/active_support/core_ext/object_and_class.rb
@@ -1,19 +1,10 @@
class Object #:nodoc:
def remove_subclasses_of(*superclasses)
subclasses_of(*superclasses).each do |subclass|
- subclass.instance_variables.each { |v| subclass.send(:remove_instance_variable, v) }
Object.send(:remove_const, subclass.to_s) rescue nil
end
end
- def remove_instance_variables_of(klass)
- ObjectSpace.each_object(Class) do |k|
- if k.to_s == klass
- k.instance_variables.each { |v| k.send(:remove_instance_variable, v) }
- end
- end
- end
-
def subclasses_of(*superclasses)
subclasses = []
ObjectSpace.each_object(Class) do |k|
View
46 activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -5,27 +5,6 @@ class ClassA; end
class ClassB < ClassA; end
class ClassC < ClassB; end
class ClassD < ClassA; end
-class RemoveSubsTestClass; end
-class RemoveSubsBaseClass
- def self.add_ivar
- @ivar = RemoveSubsTestClass.new
- end
-end
-class RemoveSubsSubClass < RemoveSubsBaseClass; end
-class RemoveSubsTestClass2; end
-class RemoveSubsBaseClass2
- def self.add_ivar
- @ivar = RemoveSubsTestClass2.new
- end
-end
-class RemoveSubsSubClass2 < RemoveSubsBaseClass2; end
-class RemoveSubsTestClass3; end
-class RemoveSubsBaseClass3
- def self.add_ivar
- @ivar = RemoveSubsTestClass3.new
- end
-end
-class RemoveSubsSubClass3 < RemoveSubsBaseClass3; end
class ClassExtTest < Test::Unit::TestCase
def test_methods
@@ -51,29 +30,4 @@ def test_suppress_supresses
suppress(LoadError, ArgumentError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
-
- def test_remove_subclasses_of_unsets_ivars
- r = RemoveSubsSubClass.new
- RemoveSubsSubClass.add_ivar
- RemoveSubsBaseClass.remove_subclasses
-
- GC.start
- ObjectSpace.each_object do |o|
- flunk("ObjectSpace still contains RemoveSubsTestClass") if o.class == RemoveSubsTestClass
- end
- end
-
- def test_remove_subclasses_of_multiple_classes_unsets_ivars
- r2 = RemoveSubsSubClass2.new
- RemoveSubsSubClass2.add_ivar
- r3 = RemoveSubsSubClass3.new
- RemoveSubsSubClass3.add_ivar
-
- Object.remove_subclasses_of(RemoveSubsBaseClass2, RemoveSubsBaseClass3)
-
- GC.start
- ObjectSpace.each_object do |o|
- flunk("ObjectSpace still contains RemoveSubsTestClass") if o.class == RemoveSubsTestClass
- end
- end
end
View
1 railties/lib/dispatcher.rb
@@ -38,6 +38,7 @@ def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFA
def reset_application!
Controllers.clear!
Dependencies.clear
+ ActiveRecord::Base.reset_subclasses
Dependencies.remove_subclasses_for(ActiveRecord::Base, ActiveRecord::Observer, ActionController::Base)
Dependencies.remove_subclasses_for(ActionMailer::Base) if defined?(ActionMailer::Base)
end

0 comments on commit 6a51940

Please sign in to comment.