aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-02 19:21:19 -0700
committerwycats <wycats@gmail.com>2010-04-02 19:21:19 -0700
commitb29e89368841869c92d706addddd09f436a3ea2f (patch)
tree3a19c59db4e1f489de43d0a04d53f3f71a6e827b
parentc6372d604952a8eef16ce73a06814aa143b94779 (diff)
downloadrails-b29e89368841869c92d706addddd09f436a3ea2f.tar.gz
rails-b29e89368841869c92d706addddd09f436a3ea2f.tar.bz2
rails-b29e89368841869c92d706addddd09f436a3ea2f.zip
Fix memory leak in dev mode
-rw-r--r--actionpack/lib/action_view/template.rb9
-rw-r--r--actionpack/test/template/render_test.rb8
2 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 8abc1633ff..3df2bd8eed 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -18,6 +18,14 @@ module ActionView
attr_reader :source, :identifier, :handler, :virtual_path, :formats
+ def self.finalizer_for(method_name)
+ proc do
+ ActionView::CompiledTemplates.module_eval do
+ remove_possible_method method_name
+ end
+ end
+ end
+
def initialize(source, identifier, handler, details)
@source = source
@identifier = identifier
@@ -98,6 +106,7 @@ module ActionView
begin
ActionView::CompiledTemplates.module_eval(source, identifier, line)
+ ObjectSpace.define_finalizer(self, self.class.finalizer_for(method_name))
method_name
rescue Exception => e # errors from template code
if logger = (view && view.logger)
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index e54ebfbf8d..5f33c933db 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -281,6 +281,10 @@ class CachedViewRenderTest < ActiveSupport::TestCase
assert_equal ActionView::FileSystemResolver, view_paths.first.class
setup_view(view_paths)
end
+
+ def teardown
+ GC.start
+ end
end
class LazyViewRenderTest < ActiveSupport::TestCase
@@ -294,4 +298,8 @@ class LazyViewRenderTest < ActiveSupport::TestCase
assert_equal ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH), view_paths.first
setup_view(view_paths)
end
+
+ def teardown
+ GC.start
+ end
end