Skip to content

@brianmario /gist:308003
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
commit b67ed0cc42e751a99f308f3b61604208fb0f5d74
Author: Brian Lopez <seniorlopez@gmail.com>
Date: Thu Feb 18 13:00:09 2010 -0800
fix memory leaks in ActionPack when cache_classes is disabled
diff --git a/actionpack/lib/abstract_controller/localized_cache.rb b/actionpack/lib/abstract_controller/localized_cache.rb
index 5e3efa0..5f81674 100644
--- a/actionpack/lib/abstract_controller/localized_cache.rb
+++ b/actionpack/lib/abstract_controller/localized_cache.rb
@@ -3,7 +3,8 @@ module AbstractController
@hash_keys = Hash.new {|h,k| h[k] = Hash.new {|sh,sk| sh[sk] = {} } }
def self.get(klass, formats, locale)
- @hash_keys[klass][formats][locale] ||= new(klass, formats, locale)
+ hash_key = Rails.application.config.cache_classes ? @hash_keys[klass][formats] : {}
+ hash_key[locale] ||= new(klass, formats, locale)
end
attr_accessor :hash
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 4fd37e7..b9c454b 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -82,7 +82,8 @@ module ActionController
@@endpoints = Hash.new {|h,k| h[k] = Hash.new {|sh,sk| sh[sk] = {} } }
def self.for(controller, action, stack)
- @@endpoints[controller][action][stack] ||= begin
+ endpoint = Rails.application.config.cache_classes ? @@endpoints[controller][action] : {}
+ endpoint[stack] ||= begin
endpoint = new(controller, action)
stack.build(endpoint)
end
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 8b6dce0..67f36b4 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -180,7 +180,7 @@ module ActionView
def initialize(view_context, options, block)
@view = view_context
- @partial_names = PARTIAL_NAMES[@view.controller.class]
+ @partial_names = Rails.application.config.cache_classes ? PARTIAL_NAMES[@view.controller.class] : {}
key = Thread.current[:format_locale_key]
@templates = TEMPLATES[key] if key
# add to the end of your controller to see the leaks
Rails.logger.debug ActionView::Partials::PartialRenderer::PARTIAL_NAMES.inspect
Rails.logger.debug AbstractController::HashKey.instance_variable_get(:@hash_keys).inspect
Rails.logger.debug ActionController::Metal::ActionEndpoint.send(:class_variable_get, :@@endpoints).inspect
Rails.logger.debug ObjectSpace.each_object(Class).map{|c| c if c.ancestors.find{|o| o.to_s == 'ApplicationController'}}.compact.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.