From: "skhrshin (Shintaro Sakahara) via ruby-core" Date: 2024-05-12T06:09:40+00:00 Subject: [ruby-core:117842] [Ruby master Bug#20485] Simple use of Fiber makes GC leak objects with singleton method Issue #20485 has been updated by skhrshin (Shintaro Sakahara). Subject changed from Simple use of Mutex and Fiber makes GC leak objects with singleton method to Simple use of Fiber makes GC leak objects with singleton method Description updated Update: Using Mutex was not necessary. ---------------------------------------- Bug #20485: Simple use of Fiber makes GC leak objects with singleton method https://bugs.ruby-lang.org/issues/20485#change-108246 * Author: skhrshin (Shintaro Sakahara) * Status: Open * ruby -v: ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I found a possible memory leak which occurs only when several conditions are met. The code to reproduce the problem is below: ``` class Work def add_method singleton_class.define_method(:f) {} end end 1.times { Fiber.new {}.resume } work = Work.new work.add_method work = nil GC.start num_objs = ObjectSpace.each_object.select { |o| o.is_a?(Work) rescue false }.size unless num_objs.zero? raise "NG" end ``` Expected result: The script exits normally. Actual result: RuntimeError "NG" is raised. If I change `1.times { Fiber.new {}.resume }` to `Fiber.new {}.resume` or remove `work.add_method`, GC works as expected. Is there any problem at the way to Fiber in this code, or is it a bug due to Ruby? I tested ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux] too and the result was same. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/