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 when exception is raised during JSON generation #574

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

peterzhu2118
Copy link
Member

If an exception is raised the FBuffer is leaked.

For example, the following script leaks memory:

o = Object.new
def o.to_json(a) = raise

10.times do
  100_000.times do
    begin
      JSON(o)
    rescue
    end
  end

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

Before:

31824
35696
40240
44304
47424
50944
54000
58384
62416
65296

After:

24416
24640
24640
24736
24736
24736
24736
24736
24736
24736

If an exception is raised the FBuffer is leaked.

For example, the following script leaks memory:

    o = Object.new
    def o.to_json(a) = raise

    10.times do
      100_000.times do
        begin
          JSON(o)
        rescue
        end
      end

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

Before:

    31824
    35696
    40240
    44304
    47424
    50944
    54000
    58384
    62416
    65296

After:

    24416
    24640
    24640
    24736
    24736
    24736
    24736
    24736
    24736
    24736
@hsbt hsbt merged commit 9ac5829 into ruby:master Mar 22, 2024
63 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants