Skip to content

Instantly share code, notes, and snippets.

@jhuckabee
Last active December 19, 2015 16:08
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 jhuckabee/5981406 to your computer and use it in GitHub Desktop.
Save jhuckabee/5981406 to your computer and use it in GitHub Desktop.
More state_machine gem memory profiling...
class HM < Module ; end
class Machine
def initialize(owner_class)
@helpers = helpers = {
:instance => HM.new,
:class => HM.new
}
owner_class.class_eval do
extend helpers[:class]
include helpers[:instance]
end
@helpers[:instance].class_eval do
# Comment out this define_method block, and
# garbage collection works as expected
define_method('test_dynamic_method') do
puts 'test'
end
end
end
end
c = Class.new do
@machine = Machine.new(self)
end
cid = c.object_id
c = nil
GC.start
GC.start # Have to do it twice
begin
puts "Anonymous class still exists. #{ObjectSpace._id2ref(cid)}"
rescue
puts "Anonymous class has been garbage collected"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment