Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active October 7, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/88d391fa64e2c45b9a9ca095d705d2e0 to your computer and use it in GitHub Desktop.
Save SamSaffron/88d391fa64e2c45b9a9ca095d705d2e0 to your computer and use it in GitHub Desktop.
# 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