Last active
December 19, 2015 15:48
-
-
Save jhuckabee/5978668 to your computer and use it in GitHub Desktop.
Trying to track down state machine memory leak on anonymous classes.
This file contains hidden or 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
require 'state_machine' | |
# Without state machine | |
regular_class = Class.new | |
regular_class_id = regular_class.object_id | |
regular_class = nil | |
# With state machine | |
machine_class = Class.new | |
machine_class.state_machine(:initial => :parked) do | |
transition({:parked => :idling, :idling => :on, :on => :parked}) | |
end | |
machine_class_id = machine_class.object_id | |
machine_class = nil | |
GC.start | |
GC.start # Must be called twice | |
begin | |
p "Regular class still exists: #{ObjectSpace._id2ref(regular_class_id)}" | |
rescue | |
p "Regular class garbage collected!" | |
end | |
begin | |
p "State machine class still exists: #{ObjectSpace._id2ref(machine_class_id)}" | |
rescue | |
p "State machine class garbage collected!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment