Post

For a while I searched a way to reliably GC an object on CRuby, this is hard given CRuby uses a conservative GC and might keep it alive via the native stack or some register. This seems reliable: m = ObjectSpace::WeakMap.new Thread.new { m[Object.new] = Object.new }.join GC.start p m.keys # => []

0 reposts1 like

The idea is that the native stack is gone since we join the Thread (or at least it won't be scanned by the GC) and the registers will reflect the current Thread. `Fiber.new {}.resume` might work too.