This repository was archived by the owner on Mar 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -107,11 +107,16 @@ def object_space # :nodoc:
107
107
# Simulate garbage collection of the objects passed in as arguments. If no objects
108
108
# are specified, all objects will be reclaimed.
109
109
def gc ( *objects )
110
- objects = object_space . keys if objects . empty?
111
- objects . each do |obj |
112
- finalizers = object_space . delete ( obj . __id__ )
110
+ objects = if objects . empty?
111
+ object_space . keys
112
+ else
113
+ objects . map { |obj | obj . __id__ }
114
+ end
115
+
116
+ objects . each do |id |
117
+ finalizers = object_space . delete ( id )
113
118
if finalizers
114
- finalizers . each { |finalizer | finalizer . call ( obj . __id__ ) }
119
+ finalizers . each { |finalizer | finalizer . call ( id ) }
115
120
end
116
121
end
117
122
end
Original file line number Diff line number Diff line change
1
+ require File . expand_path ( "../test_helper" , __FILE__ )
2
+
3
+ class TestMock < Test ::Unit ::TestCase
4
+ def test_gc_with_argument
5
+ Ref ::Mock . use do
6
+ obj_1 = Object . new
7
+ obj_2 = Object . new
8
+
9
+ ref_1 = Ref ::WeakReference . new ( obj_1 )
10
+ ref_2 = Ref ::WeakReference . new ( obj_2 )
11
+
12
+ Ref ::Mock . gc ( obj_1 )
13
+
14
+ assert_nil ref_1 . object
15
+ assert_equal ref_2 . object , obj_2
16
+ end
17
+ end
18
+
19
+ def test_gc_with_no_argument
20
+ Ref ::Mock . use do
21
+ obj_1 = Object . new
22
+ obj_2 = Object . new
23
+
24
+ ref_1 = Ref ::WeakReference . new ( obj_1 )
25
+ ref_2 = Ref ::WeakReference . new ( obj_2 )
26
+
27
+ Ref ::Mock . gc
28
+
29
+ assert_nil ref_1 . object
30
+ assert_nil ref_2 . object
31
+ end
32
+ end
33
+ end
You can’t perform that action at this time.
0 commit comments