Strange situation: last 3 requests and responses are stored in memory!


We recently spotted strange behavior with Rails 2.3. For some reason last 3
requests/responses (and all connected objects - controller, views,
controller's instance variables, etc) are always present in memory in
_production_ mode.

This is how we see the problem. Create an empty Rails application with a
simple controller like this:

=== app/controllers/default_controller.rb ===
class A

class DefaultController < ApplicationController

     def index
         @a =
         x = 0
         ObjectSpace.each_object(A) do |o|
         puts x
         render :text => "Hello!"


Now launch the application (in a production mode) and perform requests.
You'll see that:
- after first request: there's one object of class A in memory
- after second request: there're two objects of class A in memory!!!
- after third request: there're three objects of class A in memory!!!
- after Nth request: there're still three objects of class A in memory!!!

The complete log output will look like this:

On my system (ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-
darwin10.3.0]), your example maxes out at two copies of A, which is
not _that_ strange. The previous requests' objects could still be
referenced on the stack somewhere or maybe somewhere in WEBrick's

You can use memprof to figure out where the references are coming
from, but I would consider 2-3 GC calls to get rid of references to
old request objects to be normal.