Skip to content

Conversation

@rhenium
Copy link
Member

@rhenium rhenium commented Oct 31, 2025

Commit 44df509 fixed it for StandardError, but other exceptions and jumps are also possible. Use rb_ensure() to release FBuffer instead of rb_rescue().

A reproducer:

o = Object.new
def o.to_json(a) = throw :a
a = ["make heap allocation"*100, o]

10.times do
  100_000.times do
    catch(:a) { JSON(a) }
  end

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

Commit 44df509 fixed it for StandardError, but other exceptions and
jumps are also possible. Use rb_ensure() to release FBuffer instead of
rb_rescue().

A reproducer:

    o = Object.new
    def o.to_json(a) = throw :a
    a = ["make heap allocation"*100, o]

    10.times do
      100_000.times do
        catch(:a) { JSON(a) }
      end

      puts `ps -o rss= -p #{$$}`
    end
@byroot byroot merged commit e1f4224 into ruby:master Oct 31, 2025
37 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