Skip to content

Instantly share code, notes, and snippets.

@ehrenmurdick
Created March 27, 2017 22:35
Show Gist options
  • Save ehrenmurdick/b527beb0de8c527e3a3e39893debd814 to your computer and use it in GitHub Desktop.
Save ehrenmurdick/b527beb0de8c527e3a3e39893debd814 to your computer and use it in GitHub Desktop.
N = 10_000_000
class Foo
def initialize
@ary = (0..N).map { Object.new }
end
def a
# this is a closure that has captured self
define_singleton_method("O_o") {}
end
end
def wat
Foo.new.a
end
wat
GC.start
# memory doen't go down!!
# my theory is that the object is captured in the proc,
# then the eigenclass is always "reachable" according to the ruby
# mark and sweep GC because it's in the real class heiarchy,
# so the closed-in self is always "reachable", so the object
# is never marked
puts "sleeping"
sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment