Created
February 3, 2014 21:17
-
-
Save sycobuny/8792597 to your computer and use it in GitHub Desktop.
Checking whether Class.new makes permanent refs (with cribbing from https://gist.github.com/rjackson/5071864 h/t @nevern02)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def m(m) | |
puts m | |
puts " Currently at: #{`ps -o rss= -p #$$`.to_i / 1024} MB" | |
puts " #{GC.stat.inspect}" | |
end | |
m 'Started'; | |
10_000_000.times { Class.new } | |
m 'Made 10,000,000 (unstored) objects' | |
GC.start | |
m 'Ran GC' | |
a = [] | |
10_000_000.times { a << Class.new } | |
m 'Made 10,000,000 (stored) objects' | |
a = nil | |
m 'Dereferenced the array' | |
GC.start | |
m 'Ran GC' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started | |
Currently at: 5 MB | |
{:count=>3, :heap_used=>77, :heap_length=>77, :heap_increment=>0, :heap_live_num=>15152, :heap_free_num=>16321, :heap_final_num=>3} | |
Made 10,000,000 (unstored) objects | |
Currently at: 12 MB | |
{:count=>1144, :heap_used=>77, :heap_length=>77, :heap_increment=>0, :heap_live_num=>7536, :heap_free_num=>23941, :heap_final_num=>0} | |
Ran GC | |
Currently at: 12 MB | |
{:count=>1145, :heap_used=>77, :heap_length=>77, :heap_increment=>0, :heap_live_num=>7314, :heap_free_num=>24158, :heap_final_num=>0} | |
Made 10,000,000 (stored) objects | |
Currently at: 2021 MB | |
{:count=>1271, :heap_used=>48942, :heap_length=>87251, :heap_increment=>38309, :heap_live_num=>19815516, :heap_free_num=>191975, :heap_final_num=>0} | |
Dereferenced the array | |
Currently at: 2021 MB | |
{:count=>1271, :heap_used=>48942, :heap_length=>87251, :heap_increment=>38309, :heap_live_num=>19815516, :heap_free_num=>191975, :heap_final_num=>0} | |
Ran GC | |
Currently at: 673 MB | |
{:count=>1272, :heap_used=>31894, :heap_length=>87251, :heap_increment=>38309, :heap_live_num=>7314, :heap_free_num=>13030950, :heap_final_num=>0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment