Created
March 27, 2017 22:35
-
-
Save ehrenmurdick/b527beb0de8c527e3a3e39893debd814 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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