Skip to content

Instantly share code, notes, and snippets.

@niamster
Created February 21, 2015 19:00
Show Gist options
  • Save niamster/9f8dc8fb510164fbbc9c to your computer and use it in GitHub Desktop.
Save niamster/9f8dc8fb510164fbbc9c to your computer and use it in GitHub Desktop.
Test if celluloid actor is properly GCed once terminated
#!/usr/bin/env ruby
require 'celluloid'
require 'weakref'
class Test
begin
include Celluloid
finalizer :shutdown
rescue
end
def initialize
ObjectSpace.define_finalizer(self, self.class.finalize)
end
def self.finalize
proc { p "finilize" }
end
def shutdown
p "shutdown"
end
def terminate
p "stub if celluloid is not includeed"
end
end
test = Test.new
test.terminate
weak = WeakRef.new test
test = nil
loop do
GC.start(full_mark: true, immediate_sweep: true)
break unless weak.weakref_alive?
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment