Project

General

Profile

Actions

Bug #20162

closed

Memory leak when duplicating too complex object

Added by peterzhu2118 (Peter Zhu) 4 months ago. Updated 4 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116078]

Description

GitHub PR: https://github.com/ruby/ruby/pull/9449

Creating a ST table then calling st_replace leaks memory because the st_replace overwrites the ST table without freeing any of the existing memory. This commit changes it to use st_copy instead.

For example:

RubyVM::Shape.exhaust_shapes

o = Object.new
o.instance_variable_set(:@a, 0)

10.times do
  100_000.times { o.dup }

  puts `ps -o rss= -p #{$$}`
end

Before:

23264
33600
42672
52160
61600
71728
81056
90528
100560
109840

After:

14752
14816
15584
15584
15664
15664
15664
15664
15664
15664
Actions #1

Updated by peterzhu2118 (Peter Zhu) 4 months ago

  • Status changed from Open to Closed

Applied in changeset git|82b57d7bfeefd717c10f7a5a3484aca6b3e708a3.


Fix memory leak when duplicating too complex object

[Bug #20162]

Creating a ST table then calling st_replace leaks memory because the
st_replace overwrites the ST table without freeing any of the existing
memory. This commit changes it to use st_copy instead.

For example:

RubyVM::Shape.exhaust_shapes

o = Object.new
o.instance_variable_set(:@a, 0)

10.times do
  100_000.times { o.dup }

  puts `ps -o rss= -p #{$$}`
end

Before:

23264
33600
42672
52160
61600
71728
81056
90528
100560
109840

After:

14752
14816
15584
15584
15664
15664
15664
15664
15664
15664

Updated by naruse (Yui NARUSE) 4 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED to 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: DONE

ruby_3_3 3fb51b93d25b0566b71249b1c7ccddf0dab91429 merged revision(s) 82b57d7bfeefd717c10f7a5a3484aca6b3e708a3.

Actions

Also available in: Atom PDF

Like0
Like0Like0