rails 3.2 app with 2 models and script to repro AR memory leak
Ruby JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.rbx
app
config
db
doc
lib
log
public
script
test
vendor
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru
htenu

README.md

ActiveRecord memory leak

The intent of this simple app is to try to reproduce a memory leak on ActiveRecord.

This leak is present on all versions of Rails 3, including the latest as of this time, 3.2.6.

The script

You can run the script in lib/leak.rb.

The script can be run either with rails through rails r lib/leak.rb or ruby alone ruby lib/leak.rb.

When run without rails, the script creates objects that mimic the AR models, and show the difference in object count.

Results

A detailed example run can be found in this gist.

This is a short summary of running the script:

Final) MyModel -> 200, MyAssociation -> 100 (1 is fine, 2+ is leak) # Rails + MRI 1.9
Final) MyModel -> 100, MyAssociation -> 9 (1 is fine, 2+ is leak) # Rails + Rubinius

Final) MyModel -> 1, MyAssociation -> 1 (1 is fine, 2+ is leak) # MRI 1.9
Final) MyModel -> 0, MyAssociation -> 0 (1 is fine, 2+ is leak) # Rubinius
Final) MyModel -> 0, MyAssociation -> 0 (1 is fine, 2+ is leak) # MRI 1.8
Final) MyModel -> 0, MyAssociation -> 0 (1 is fine, 2+ is leak) # JRuby