From: "jhawthorn (John Hawthorn) via ruby-core" Date: 2024-07-16T18:31:27+00:00 Subject: [ruby-core:118620] [Ruby master Bug#20638] Threads not collected by GC under RUBY_MN_THREADS=1 Issue #20638 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #20638: Threads not collected by GC under RUBY_MN_THREADS=1 https://bugs.ruby-lang.org/issues/20638 * Author: jhawthorn (John Hawthorn) * Status: Open * ruby -v: ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- When running with `RUBY_MN_THREADS=1` I noticed increased memory usage when creating many threads. It seems like Threads aren't able to be collected when run concurrently. ``` $ ruby -e '500.times { 50.times.map { Thread.new{} }.map(&:join) }; sleep 1; GC.start; p ObjectSpace.each_object(Thread).count' 1 $ RUBY_MN_THREADS=1 ruby -e '500.times { 50.times.map { Thread.new{} }.map(&:join) }; sleep 1; GC.start; p ObjectSpace.each_object(Thread).count' 24501 ``` (Note that 24500 is 500 * 49. It seems like each time we make the 50 concurrent threads 49 of them leak) I tested both on macos and linux and this occurs both on Ruby 3.3 and head. No combination of sleeping or GC seems to clear them. According to a heap dump these are being held in memory by the VM root. -- 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/lists/ruby-core.ml.ruby-lang.org/