File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,9 @@ def self.of(root)
6161 size += ObjectSpace . memsize_of ( object )
6262
6363 # Add the object's reachable objects to the queue:
64- queue . concat ( ObjectSpace . reachable_objects_from ( object ) )
64+ if reachable_objects = ObjectSpace . reachable_objects_from ( object )
65+ queue . concat ( reachable_objects )
66+ end
6567 end
6668
6769 return new ( size , count )
Original file line number Diff line number Diff line change 11# Releases
22
3+ ## Unreleased
4+
5+ - Handle ` Memory::Usage.of(number) ` without error.
6+
37## v0.8.2
48
59 - Fix several formatting issues.
Original file line number Diff line number Diff line change 44# Copyright, 2022-2025, by Samuel Williams.
55
66require "memory/usage"
7+ require "json"
78
89describe Memory ::Usage do
910 let ( :usage ) { subject . new }
139140 size : be > 0
140141 )
141142 end
143+
144+ it "can compute usage of nil" do
145+ usage = subject . of ( nil )
146+ expect ( usage ) . to have_attributes (
147+ count : be == 0 ,
148+ size : be == 0
149+ )
150+ end
151+
152+ it "can compute usage of numbers" do
153+ usage = subject . of ( 42 )
154+ expect ( usage ) . to have_attributes (
155+ count : be == 1 ,
156+ size : be == 0
157+ )
158+ end
142159 end
143160
144161 with "#to_s" do
You can’t perform that action at this time.
0 commit comments