Skip to content
  • Peter Zhu's avatar
    417b1a36
    Fix memory leak for iclass · 417b1a36
    Peter Zhu authored
    [Bug #19550]
    
    If !RCLASS_EXT_EMBEDDED (e.g. 32 bit systems) then the rb_classext_t is
    allocated throug malloc so it must be freed.
    
    The issue can be seen in the following script:
    
    ```
    20.times do
      100_000.times do
        mod = Module.new
        Class.new do
          include mod
        end
      end
    
      # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
      puts `ps -o rss= -p #{$$}`
    end
    ```
    
    Before this fix, the max RSS is 280MB, while after this change, it's
    30MB.
    417b1a36
    Fix memory leak for iclass
    Peter Zhu authored
    [Bug #19550]
    
    If !RCLASS_EXT_EMBEDDED (e.g. 32 bit systems) then the rb_classext_t is
    allocated throug malloc so it must be freed.
    
    The issue can be seen in the following script:
    
    ```
    20.times do
      100_000.times do
        mod = Module.new
        Class.new do
          include mod
        end
      end
    
      # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
      puts `ps -o rss= -p #{$$}`
    end
    ```
    
    Before this fix, the max RSS is 280MB, while after this change, it's
    30MB.
Loading