Q:

Is there a theoretical limit to the number of objects Ruby can store?

At least up to a little more than 20_000_000, the object_ids 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.

A:

How object ids are allocated is implementation dependant. On C-ruby, object id is just the numerical value of the memory address of the object (with some exceptions for immediate values such as true, false, nil, Fixnums).
Therefore two live objects can't share the same object id (good!), however if you trigger a garbage collection then some of the memory locations (i.e. heap slots) may be reused and therefore the object ids too.
Another consequence is that you'll never run out of object ids (unless you exhaust the address space of the process, but you're in trouble anyway if that happens)

