
Issue #19460 has been reported by luke-gru (Luke Gruber). ---------------------------------------- Bug #19460: inline method cache won't let class be garbage collected https://bugs.ruby-lang.org/issues/19460 * Author: luke-gru (Luke Gruber) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- I'm working on something where I need to remove a class and release all memory related to that class. I've stumbled upon a limitation where in some instances I cannot get the class to be GC'd. The problem (I think) is that inline method caches cache the class, and even if the class would otherwise be gone, it stays. For example: ```ruby class A def do_something self.call_other # inline cache caches class A, so now A is marked every time cache is marked end def call_other end end a = A.new a.send(:do_something) # don't make normal call, use send so no inline cache used here a_id = A.object_id a = nil Object.send(:remove_const, :A) # A should be able to be released now. 10.times { GC.start } a_ref = ObjectSpace._id2ref(a_id) rescue nil puts "a_ref: #{a_ref.class}" ```ruby One solution to this would be if inline caches are inside methods, only mark them when the method itself is marked. I'm guessing they're marked independently right now. -- https://bugs.ruby-lang.org/