Ruby GC is not a black box. Once you understand how it works, you can either change your code to put less strain on it, or you can tune GC up for better performance. Here’s what you need to keep in mind:
Ruby allocates objects on a dedicated heap space, which it manages itself.
Each object has the fixed amount of storage (40 bytes on 64-bit computers). If the object needs more memory, it allocates that on the operating system heap.
Ruby runs GC when it decides that it allocated too many objects or its objects allocated too much memory. Correspondingly, there are two criteria for this decision. First, Ruby heap space doesn’t have enough free slots. Second, the current memory allocation (malloc) limit has been exceeded.
You can ...