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

[Bug #20145] Memory leak when duplicating identhash #9411

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

peterzhu2118
Copy link
Member

Before this commit, both copy_compare_by_id and hash_copy will create a copy of the ST table, so the ST table created in copy_compare_by_id will be leaked.

h = { 1 => 2 }.compare_by_identity

10.times do
  1_000_000.times do
    h.select { false }
  end

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

Before:

110736
204352
300272
395520
460704
476736
542000
604704
682624
770528

After:

15504
16048
16144
16256
16320
16320
16752
16752
16752
16752

[Bug #20145]

Before this commit, both copy_compare_by_id and hash_copy will create a
copy of the ST table, so the ST table created in copy_compare_by_id will
be leaked.

    h = { 1 => 2 }.compare_by_identity

    10.times do
      1_000_000.times do
        h.select { false }
      end

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

Before:

    110736
    204352
    300272
    395520
    460704
    476736
    542000
    604704
    682624
    770528

After:

    15504
    16048
    16144
    16256
    16320
    16320
    16752
    16752
    16752
    16752
@peterzhu2118 peterzhu2118 changed the title [Bug #20113] Memory leak when duplicating identhash [Bug #20145] Memory leak when duplicating identhash Jan 3, 2024
@peterzhu2118 peterzhu2118 merged commit 6c25291 into ruby:master Jan 4, 2024
94 checks passed
@peterzhu2118 peterzhu2118 deleted the hash-compare-by-id-mem-leak branch January 4, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant