diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2024-01-18 10:36:49 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2024-01-18 13:40:14 -0500 |
| commit | d8ac96efc57be460a0aad5d6ae033639439506fb (patch) | |
| tree | eff2bf059a628de82b82d46ac253be4bf28905ef /test/ruby | |
| parent | d3b07b984545ce156e02e9f71404b652c6cb5284 (diff) | |
[PRISM] Fix memory leak in case nodes
The temporary array conditions_labels is heap allocated and never freed.
We can use alloca instead to stack allocate it so that we don't need to
manually free it.
For example:
code = "case; #{100.times.map { "when #{it}; " }.join}; end"
10.times do
10_000.times do
RubyVM::InstructionSequence.compile_prism(code)
end
puts `ps -o rss= -p #{$$}`
end
Before:
21376
30304
38800
47184
55456
64192
72288
80400
89040
97104
After:
13088
13632
13760
14016
14688
14992
15120
15232
15744
15744
Diffstat (limited to 'test/ruby')
0 files changed, 0 insertions, 0 deletions
