Permalink
Browse files

Fix memory leak in dev mode

  • Loading branch information...
1 parent c6372d6 commit b29e89368841869c92d706addddd09f436a3ea2f @wycats wycats committed Apr 3, 2010
Showing with 17 additions and 0 deletions.
  1. +9 −0 actionpack/lib/action_view/template.rb
  2. +8 −0 actionpack/test/template/render_test.rb
@@ -18,6 +18,14 @@ class Template
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 @@ def #{method_name}(local_assigns)
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)
@@ -281,6 +281,10 @@ def setup
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 @@ def setup
assert_equal ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH), view_paths.first
setup_view(view_paths)
end
+
+ def teardown
+ GC.start
+ end
end

0 comments on commit b29e893

Please sign in to comment.