Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit a191208

Browse files
author
Brian Durand
committed
clear object on ref when it is no longer found
1 parent dcbfda9 commit a191208

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/ref/safe_monitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def unlock
3333
@count -= 1
3434
if @count == 0
3535
@owner = nil
36-
@mutex.unlock rescue puts "current #{Thread.current.object_id}; owner #{@owner}"
36+
@mutex.unlock
3737
end
3838
end
3939
end

lib/ref/weak_reference/pure_ruby.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ def initialize(obj) #:nodoc:
7575
# Get the reference object. If the object has already been garbage collected,
7676
# then this method will return nil.
7777
def object #:nodoc:
78-
@reference_pointer.object
78+
if @reference_pointer
79+
obj = @reference_pointer.object
80+
unless obj
81+
@@lock.synchronize do
82+
@@weak_references.delete(object_id)
83+
@reference_pointer.cleanup
84+
@reference_pointer = nil
85+
end
86+
end
87+
obj
88+
end
7989
end
8090
end
8191
end

0 commit comments

Comments
 (0)