Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge revision(s) 82b57d7bfeefd717c10f7a5a3484aca6b3e708a3: [Backport… #9795

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

nurse
Copy link
Member

@nurse nurse commented Feb 1, 2024

… #20162]

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
---
 object.c                 |  3 +--
 test/ruby/test_shapes.rb | 13 +++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

	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
	---
	 object.c                 |  3 +--
	 test/ruby/test_shapes.rb | 13 +++++++++++++
	 2 files changed, 14 insertions(+), 2 deletions(-)
@nurse nurse added this pull request to the merge queue Feb 1, 2024
Merged via the queue into ruby:ruby_3_3 with commit 3fb51b9 Feb 1, 2024
80 of 82 checks passed
@nurse nurse deleted the backport-20162 branch February 1, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant