Skip to content

Commit

Permalink
Fix memory leak in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Apr 3, 2010
1 parent c6372d6 commit b29e893
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions actionpack/lib/action_view/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.