Skip to content

Instantly share code, notes, and snippets.

@matthewd
Created October 9, 2015 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewd/3d78bae0ebebdc20981e to your computer and use it in GitHub Desktop.
Save matthewd/3d78bae0ebebdc20981e to your computer and use it in GitHub Desktop.
require 'active_record'
Bundler.require :default
require 'objspace'
ObjectSpace.trace_object_allocations_start
def iter n
if n > 0
1.times{
iter(n-1)
}
else
# null code
end
end
def gc
iter(100)
GC.start
GC.start
end
class TestClass
def foo
require 'net/telnet'
end
end
def do_the_thing
x = TestClass.new
x.foo
nil
end
do_the_thing
# This fixes it:
#require 'net/smtp'
gc
n = Hash.new(0); ObjectSpace.each_object(TestClass) {|o| n[o.class.name] += 1 }; p Hash[n.sort]
gc
puts ObjectSpace.dump_all.path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment