blob: 4a362740ca94ca7db626719a0bfad99d698aadcd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
assert('ObjectSpace.count_objects') do
h = {}
ObjectSpace.count_objects(h)
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
assert_true(h.has_key?(:TOTAL))
assert_true(h.has_key?(:FREE))
p h.inspect
h = ObjectSpace.count_objects
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
p h.inspect
h0 = {:MRB_TT_FOO=>1000}
h = ObjectSpace.count_objects(h0)
assert_false(h0.has_key?(:MRB_TT_FOO))
GC.start
h_after = {}
h_before = ObjectSpace.count_objects
objs = []
1000.times do
objs << {}
end
objs = nil
ObjectSpace.count_objects(h)
GC.start
ObjectSpace.count_objects(h_after)
assert_equal(h_before[:MRB_TT_HASH] + 1000, h[:MRB_TT_HASH])
assert_equal(h_before[:MRB_TT_HASH], h_after[:MRB_TT_HASH])
p h.inspect
p h_after.inspect
end
|