There is no such thing as "memory" in Ruby.
Class#allocate selects an object and returns this object. And this is the full degree of interaction that a programmer can have with the subsystem of the object space.
If this object is selected, how it is allocated, if it remains in one place in memory or moves, none of them are indicated or observed. For example, in MagLev, an object may not be allocated in memory at all, but on a disk or other computer memory. JRuby, IronRuby, Opal, Cardinal, MacRuby, etc. They “redirect” the management of their memory to a third party, they literally do not even know what is happening with their memory.
A Ruby implementation can use a separate stack and a heap, it can use a stack allocated by a heap, it may not even use a stack at all (for example, a cardinal).
Note: The ObjectSpace module allows ObjectSpace to limit the amount of introspection and reflection of the space of objects. In general, when I say something “impossible” in Ruby, there is always a hidden warning “if you are not using reflection”. However, even ObjectSpace does not convey any information about the organization of memory.
YARV also has an objspace and GC library that provides internal information about the implementation of YARV. However, they are private internal details of the YARV implementation, they are not even guaranteed to exist in other implementations, and they can change at any time without notice even within the YARV.
You may notice that I did not write anything about garbage collection! Well, in fact, Ruby only indicates when objects are referenced and when not. What to do with objects without links, he does not say. For the implementation, it makes sense to return the space used by these objects without references, and all of them to some extent perform (for example, older versions of YARV do not return unreferenced Symbol s), but this is not required and is not indicated. And all implementations use very different approaches. Again, JRuby, IronRuby, Opal, Cardinal, MacRuby, Topaz, MagLev, etc. "Redirect" this problem to the underlying platform, Rubinius uses a collectible, copy, move, tracer compiler based on the Immix collector, YARV uses a simple label - and-tracer tracer collector.