Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement