Project

General

Profile

Actions

Bug #20638

open

Threads not collected by GC under RUBY_MN_THREADS=1

Added by jhawthorn (John Hawthorn) 4 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x86_64-linux]
[ruby-core:118620]

Description

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.

No data to display

Actions

Also available in: Atom PDF

Like0