1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/lib/action_view/template/inline.rb
Aaron Patterson 52eafbd749
Add a finalizer to inline templates
This commit adds a finalizer just to inline templates.  We can't cache
compilation of inline templates because it's possible that people could
have render calls that look like this:

```ruby
loop do
  render inline: "#{rand}"
end
```

and we would cache every one of these different inline templates.  That
would cause a memory leak.  OTOH, we don't need finalizers on regular
templates because we can cache, control, and detect changes to the
template source.

Fixes: #35372
2019-02-22 17:59:55 -08:00

22 lines
570 B
Ruby

# frozen_string_literal: true
module ActionView #:nodoc:
class Template #:nodoc:
class Inline < Template #:nodoc:
# This finalizer is needed (and exactly with a proc inside another proc)
# otherwise templates leak in development.
Finalizer = proc do |method_name, mod| # :nodoc:
proc do
mod.module_eval do
remove_possible_method method_name
end
end
end
def compile(mod)
super
ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
end
end
end
end