-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rack::GarbageCollector middleware
Calls GC.start after each request. This is a really simplistic implementation but I've found it useful in debugging potential memory leaks.
- Loading branch information
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Rack | ||
# Forces garbage collection after each request. | ||
class GarbageCollector | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
res = @app.call(env) | ||
GC.start | ||
res | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'rack/mock' | ||
require 'rack/garbagecollector' | ||
|
||
context 'Rack::GarbageCollector' do | ||
|
||
specify 'starts the garbage collector after each request' do | ||
app = lambda { |env| | ||
[200, {'Content-Type'=>'text/plain'}, ['Hello World']] } | ||
Rack::GarbageCollector.new(app).call({}) | ||
end | ||
|
||
end |