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

Fix memory leak in Ripper #7985

Merged
merged 1 commit into from
Jun 28, 2023
Merged

Conversation

peterzhu2118
Copy link
Member

The following script leaks memory in Ripper:

require "ripper"

20.times do
  100_000.times do
    Ripper.parse("")
  end

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

@nobu
Copy link
Member

nobu commented Jun 27, 2023

  def test_no_memory_leak
    assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-'end;'}", rss: true)
    require "ripper"
    code = ""
    1_000.times do
      Ripper.parse(code)
    end
    begin;
      1_000_000.times do
        Ripper.parse(code)
      end
    end;
  end

@nobu
Copy link
Member

nobu commented Jun 28, 2023

The error should be https://bugs.ruby-lang.org/issues/19748.

The following script leaks memory in Ripper:

```ruby
require "ripper"

20.times do
  100_000.times do
    Ripper.parse("")
  end

  puts `ps -o rss= -p #{$$}`
end
```
@peterzhu2118 peterzhu2118 merged commit a500eb9 into ruby:master Jun 28, 2023
92 checks passed
@peterzhu2118 peterzhu2118 deleted the pz-ripper-mem-leak branch June 28, 2023 13:50
Comment on lines +146 to +148
10_000_000.times do
Ripper.parse("")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my machine (Intel MacBookPro 2019), this caused timeouts both of before and after this commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't time out on my M1 MacBook Pro, but I can reproduce on my Linux machine. I opened #7992 which should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants