diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-02-01 09:08:57 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-02-01 13:23:55 -0500 |
commit | c6f84e918943a0bf8db6fee556fc53180d257510 (patch) | |
tree | d227af24619080a2700aaa869cd5334d3dce4650 /test/ruby | |
parent | 375f527ded72cd20374144dd605e0177945b9fae (diff) | |
download | ruby-c6f84e918943a0bf8db6fee556fc53180d257510.tar.gz |
[Bug #19398] Memory leak in WeakMap
There's a memory leak in ObjectSpace::WeakMap due to not freeing
the `struct weakmap`. It can be seen in the following script:
```
100.times do
10000.times do
ObjectSpace::WeakMap.new
end
# Output the Resident Set Size (memory usage, in KB) of the current Ruby process
puts `ps -o rss= -p #{$$}`
end
```
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_weakmap.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index 4c91661f86..86550cc221 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -167,4 +167,13 @@ class TestWeakMap < Test::Unit::TestCase assert_nothing_raised(FrozenError) {@wm[o] = 'foo'} assert_nothing_raised(FrozenError) {@wm['foo'] = o} end + + def test_no_memory_leak + assert_no_memory_leak([], '', "#{<<~"begin;"}\n#{<<~'end;'}", "[Bug #19398]", rss: true, limit: 1.5, timeout: 60) + begin; + 1_000_000.times do + ObjectSpace::WeakMap.new + end + end; + end end |