Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. N = 10_000_000
  2.  
  3. class Foo
  4. def initialize
  5. @ary = (0..N).map { Object.new }
  6. end
  7.  
  8. def a
  9. # this is a closure that has captured self
  10. define_singleton_method("O_o") {}
  11. end
  12. end
  13.  
  14. def wat
  15. Foo.new.a
  16. end
  17.  
  18. wat
  19. GC.start
  20.  
  21. # memory doen't go down!!
  22.  
  23. # my theory is that the object is captured in the proc,
  24. # then the eigenclass is always "reachable" according to the ruby
  25. # mark and sweep GC because it's in the real class heiarchy,
  26. # so the closed-in self is always "reachable", so the object
  27. # is never marked
  28.  
  29. puts "sleeping"
  30. sleep 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement