Skip to content
  • Peter Zhu's avatar
    584559d8
    Fix leak of token_info when Ripper#warn jumps · 584559d8
    Peter Zhu authored
    For example, the following code leaks:
    
        class MyRipper < Ripper
          def initialize(src, &blk)
            super(src)
            @blk = blk
          end
    
          def warn(msg, *args) = @blk.call(msg)
        end
    
        $VERBOSE = true
        def call_parse = MyRipper.new("if true\n  end\n") { |msg| return msg }.parse
    
        10.times do
          500_000.times do
            call_parse
          end
    
          puts `ps -o rss= -p #{$$}`
        end
    
    Before:
    
        37536
        53744
        70064
        86448
        102576
        119120
        135248
        151216
        167744
        183824
    
    After:
    
        19280
        19696
        19728
        20336
        20448
        21408
        21616
        21616
        21824
        21840
    584559d8
    Fix leak of token_info when Ripper#warn jumps
    Peter Zhu authored
    For example, the following code leaks:
    
        class MyRipper < Ripper
          def initialize(src, &blk)
            super(src)
            @blk = blk
          end
    
          def warn(msg, *args) = @blk.call(msg)
        end
    
        $VERBOSE = true
        def call_parse = MyRipper.new("if true\n  end\n") { |msg| return msg }.parse
    
        10.times do
          500_000.times do
            call_parse
          end
    
          puts `ps -o rss= -p #{$$}`
        end
    
    Before:
    
        37536
        53744
        70064
        86448
        102576
        119120
        135248
        151216
        167744
        183824
    
    After:
    
        19280
        19696
        19728
        20336
        20448
        21408
        21616
        21616
        21824
        21840
Loading