Last active
December 19, 2015 16:08
More state_machine gem memory profiling...
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
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