Created
September 23, 2008 22:31
-
-
Save tmm1/12434 to your computer and use it in GitHub Desktop.
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 'rubygems' | |
require 'eventmachine' | |
GC.disable | |
def Object.finalizer info = nil | |
proc{ | |
p [Time.now, :FINALIZER, info] | |
} | |
end | |
class Test | |
def initialize | |
@abc = :def | |
end | |
end | |
EM.run{ | |
def check_objects | |
EM.add_periodic_timer(1) { | |
GC.enable | |
ObjectSpace.garbage_collect | |
GC.disable | |
c = 0 | |
ObjectSpace.each_object(Test){ c+=1 } | |
p [Time.now, :OBJECTS, c] | |
} | |
end | |
def test | |
obj = Test.new | |
ObjectSpace.define_finalizer obj, Object.finalizer(obj.inspect) | |
prc = proc{ p obj; :done } | |
ObjectSpace.define_finalizer prc, Object.finalizer(prc.inspect) | |
end | |
test | |
check_objects | |
# check_objects | |
# test | |
} | |
__END__ | |
calling check_objects, then test: | |
[Tue Sep 23 15:29:04 -0700 2008, :OBJECTS, 1] | |
[Tue Sep 23 15:29:05 -0700 2008, :FINALIZER, "#<Proc:0x0033da4c@-:35>"] | |
[Tue Sep 23 15:29:05 -0700 2008, :OBJECTS, 1] | |
[Tue Sep 23 15:29:06 -0700 2008, :OBJECTS, 1] | |
[Tue Sep 23 15:29:08 -0700 2008, :OBJECTS, 1] | |
calling test, then check_objects: | |
[Tue Sep 23 15:29:16 -0700 2008, :OBJECTS, 1] | |
[Tue Sep 23 15:29:17 -0700 2008, :FINALIZER, "#<Test:0x124d230 @abc=:def>"] | |
[Tue Sep 23 15:29:17 -0700 2008, :FINALIZER, "#<Proc:0x0033da4c@-:35>"] | |
[Tue Sep 23 15:29:17 -0700 2008, :OBJECTS, 0] | |
[Tue Sep 23 15:29:19 -0700 2008, :OBJECTS, 0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment