Skip to content

Instantly share code, notes, and snippets.

@vangberg
Created July 4, 2012 16:31
Show Gist options
  • Save vangberg/3048173 to your computer and use it in GitHub Desktop.
Save vangberg/3048173 to your computer and use it in GitHub Desktop.
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rails -v
Rails 3.2.6
$ mkdir memory_leak
$ cd memory_leak
$ rails new .
$ rails g model Stub
$ bundle exec rake db:create db:migrate
$ rails runner ml.rb
In loop: 0
Not in loop: 10
require "./ml.rb"
1.times {stub_all}
GC.start
puts base_count #=> 0
require "./ml.rb"
stub_all
GC.start
puts base_count #=> 10
require "./ml.rb"
begin stub_all end
GC.start
puts base_count #=> 10
def stub_all
Stub.all.each {}
nil
end
def base_count
ObjectSpace.each_object(ActiveRecord::Base).count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment