Skip to content

Instantly share code, notes, and snippets.

@gbelote
Created September 30, 2012 12:51
Show Gist options
  • Save gbelote/3806665 to your computer and use it in GitHub Desktop.
Save gbelote/3806665 to your computer and use it in GitHub Desktop.
Fix NewRelic+Webrick memory leak
class ZThreadSweeper
def initialize(app)
@app = app
end
def call(env)
pre_keys = Thread.current.keys
result = @app.call(env)
post_keys = Thread.current.keys
# nuke
post_keys.each { |k| Thread.current[k] = nil unless pre_keys.include?(k) }
result
end
end
Rails.configuration.middleware.insert_before 0, ZThreadSweeper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment