Project

General

Profile

Actions

Bug #19460

closed

Class not able to be garbage collected

Added by luke-gru (Luke Gruber) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:112546]

Description

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:

class A
  def do_something
  end
end
a = A.send(:new)
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}"

# we get NilClass, it is released

However: using A.new above, it can't be GC'd.
If there is an initialize method (even empty) it can't be GC'd.
If there's a method call inside the class to another instance method on self ex: self.do_something, it can't be GC'd.

I'm not sure exactly what is going on but it looks like an inline cache marking issue. Maybe caches are getting marked, even inside methods where the method itself doesn't get marked.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #19041: Weakref is still alive after major garbage collectionClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0