At least up to a little more than 20_000_000
, the object_id
s of numbers are 2 times the number + 1:
1454.object_id # => 2909
When calling the object_id
on large numbers, this format is not kept. It seems like there is a built in limit to the number of objects you could theoretically have. I ran:
ids = []
100_000_000.times { ids << String.new.object_id }
ids.max # => 22314984
ids.uniq.count # => 44301
So out of the 100,000,000 string objects, only about 50,000 were actually unique. That means 99.95% of these objects were the same object. I'm not sure why this is.