Last active
October 7, 2019 10:27
-
-
Save SamSaffron/88d391fa64e2c45b9a9ca095d705d2e0 to your computer and use it in GitHub Desktop.
This file contains 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
# frozen_string_literal: true | |
require 'securerandom' | |
require 'objspace' | |
module Giant | |
end | |
def rss | |
`ps -p #{Process.pid} -o rss -h`.strip.to_i | |
end | |
def objspace_memsize | |
size = 0 | |
ObjectSpace.each_object do |o| | |
size += ObjectSpace.memsize_of(o) | |
end | |
size | |
end | |
1_000.times do | |
bloated_method = <<~METHOD | |
def _#{SecureRandom.hex} | |
#{(0..1000).map { "sleep; " }.join} | |
end | |
METHOD | |
Giant.module_eval bloated_method | |
end | |
3.times do | |
GC.start | |
end | |
puts "RSS is: #{rss}, Object Space size is: #{objspace_memsize / 1024}" | |
# RSS is: 116852, Object Space size is: 2280 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment