
Issue #20311 has been updated by byroot (Jean Boussier). I had a quick look at this using `ObjectSpace.dump_all`, and it appears that these classes are being retained in the VM root: ```ruby require 'objspace' 3.times do puts ObjectSpace.dump(Struct.new("A")) Struct.send(:remove_const, :A) end GC.start ObjectSpace.dump_all(output: File.open("/tmp/heap.json", "w+")) ``` ``` {"address":"0x102bc33f8", "type":"CLASS", .... {"address":"0x102bc3218", "type":"CLASS", .... {"address":"0x102bc3038", "type":"CLASS", .... ``` ``` $ rg -F '"0x102bc3218"' /tmp/heap.json 1:{"type":"ROOT", "root":"vm", "references":[..., "0x102bc3218" $ rg -F '"0x102bc33f8"' /tmp/heap.json 1:{"type":"ROOT", "root":"vm", "references":[..., "0x102bc33f8" ``` ---------------------------------------- Bug #20311: Struct.new("A") memory leak? https://bugs.ruby-lang.org/issues/20311#change-107049 * Author: MaxLap (Maxime Lapointe) * Status: Open * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The following code gives the impression of a memory leak. ``` 10.times do 5000.times do Struct.new("A") Struct.send(:remove_const, :A) end GC.start puts `ps -o rss= -p #{$$}`.to_i end ``` ``` 27868 35324 43400 51472 58676 66144 73764 81196 88512 95752 ``` Is there another location where the struct gets set that I need to clear up for the GC free the memory? Happens in 3.2.2, 3.2.3, 3.3.0, 3.3-head, ruby-head. -- https://bugs.ruby-lang.org/