diff options
| author | nagachika <nagachika@ruby-lang.org> | 2024-07-07 14:47:04 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2024-07-07 16:44:06 +0900 |
| commit | bd5df1693c89d389471d145fc19b487c708912b1 (patch) | |
| tree | 02aa26c8eb487a23cf867248464c19c3bbac02a0 /test/ruby | |
| parent | 2a4469ea590e6719eb30e8b7aea7e147e3b82f75 (diff) | |
merge revision(s) e626da82eae3d437b84d4f9ead0164d436b08e1a, f3af5ae7e6c1c096bbfe46d69de825a02b1696cf: [Backport #20311]
Don't pin named structs defined in Ruby
[Bug #20311]
`rb_define_class_under` assumes it's called from C and that the
reference might be held in a C global variable, so it adds the
class to the VM root.
In the case of `Struct.new('Name')` it's wasteful and make
the struct immortal.
Make Struct memory leak test faster
[Bug #20311]
It times out on some platform, so we can reduce iterations.
On my machine it completes in 250ms and RSS grows 8X.
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_struct.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 78a81c5200..8a5706b18c 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -526,6 +526,20 @@ module TestStruct assert_equal [[:req, :_]], klass.instance_method(:c=).parameters end + def test_named_structs_are_not_rooted + # [Bug #20311] + assert_no_memory_leak([], <<~PREP, <<~CODE, rss: true) + code = proc do + Struct.new("A") + Struct.send(:remove_const, :A) + end + + 1_000.times(&code) + PREP + 50_000.times(&code) + CODE + end + class TopStruct < Test::Unit::TestCase include TestStruct |
