Permalink
Browse files

Use a constant proc to generate ActionView::Template finalizers. For …

…some strange reason, finalizers created via ActionView::Template.finalizer_for cause Template instances to leak on MRI.

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information...
1 parent a8c3c71 commit af89c58696580ee26ffbd99ab9a3747fba937e35 @tmm1 tmm1 committed with wycats Apr 4, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 actionpack/lib/action_view/template.rb
@@ -18,7 +18,7 @@ class Template
attr_reader :source, :identifier, :handler, :virtual_path, :formats
- def self.finalizer_for(method_name)
+ Finalizer = proc do |method_name|
proc do
ActionView::CompiledTemplates.module_eval do
remove_possible_method method_name
@@ -77,7 +77,6 @@ def inspect
private
def compile(locals, view)
method_name = build_method_name(locals)
-
return method_name if view.respond_to?(method_name)
locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join
@@ -106,7 +105,8 @@ def #{method_name}(local_assigns)
begin
ActionView::CompiledTemplates.module_eval(source, identifier, line)
- ObjectSpace.define_finalizer(self, self.class.finalizer_for(method_name))
+ ObjectSpace.define_finalizer(self, Finalizer[method_name])
+
method_name
rescue Exception => e # errors from template code
if logger = (view && view.logger)

0 comments on commit af89c58

Please sign in to comment.