#!/usr/bin/env ruby # frozen_string_literal: true require 'bundler/setup' require "heap-profiler" require 'fileutils' require 'date' class SomeCustomStuff def initialize @root = 1 end def foo @foo = 1 end def bar @bar = 2 end end $freed_objects = [+"i am free", +"i am free too"] dir = ARGV.first FileUtils.mkdir_p(dir) FileUtils.rm_rf(Dir[File.join(dir, '*')]) if ARGV[1] == '--empty' HeapProfiler.report(dir) {} else HeapProfiler.report(dir) do SomeCustomStuff.new.tap(&:foo).tap(&:bar) SomeCustomStuff.new.tap(&:bar) $retained_objects = [ +"I am retained", +"I am retained", +"I am retained too", SomeCustomStuff.new, Date.today, ] "I am a very very long string " * 4 [ +"I am allocated", +"I am allocated too", ] $freed_objects = nil Struct.new("foo".to_sym, :bar) end end