Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (16 sloc) 1.1 KB

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
Jump to Line
Something went wrong with that request. Please try again.