Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, I found the answer. I am leaving my other answer up because that information was very difficult to gather, it is related, and it could help someone else searching for a related issue. </p> <p>Your problem, however, appears to be due to the fact that Ruby actually does <strong>not</strong> release memory back to the Operating System once it has acquired it. </p> <blockquote> <p>Memory Allocation</p> <p>While Ruby programmers do not often worry about memory allocation, sometimes the following question comes up:</p> <p>Why did my Ruby process stay so big even after I’ve cleared all references to big objects? I’m /sure/ GC has run several times and freed my big objects and I’m not leaking memory.</p> <p>A C programmer might ask the same question:</p> <p>I free()-ed a lot of memory, why is my process still so big?</p> <p>Memory allocation to user space from the kernel is cheaper in large chunks, thus user space avoids interaction with the kernel by doing more work itself.</p> <p>User space libraries/runtimes implement a memory allocator (e.g.: malloc(3) in libc) which takes large chunks of kernel memory2 and divides them up into smaller pieces for user space applications to use.</p> <p>Thus, several user space memory allocations may occur before user space needs to ask the kernel for more memory. Thus if you got a large chunk of memory from the kernel and are only using a small part of that, that large chunk of memory remains allocated.</p> <p>Releasing memory back to the kernel also has a cost. User space memory allocators may hold onto that memory (privately) in the hope it can be reused within the same process and not give it back to the kernel for use in other processes. <a href="http://blog.rubybestpractices.com/posts/ewong/005-Avoiding-system-calls.html">(Ruby Best Practices)</a></p> </blockquote> <p>So, your objects may very well have been garbage collected and released back to Ruby's available memory, but because Ruby never gives back unused memory to the OS, the rss value for the process remains the same, even after garbage collection. This is actually by design. According to <a href="http://www.mikeperham.com/2009/05/25/memory-hungry-ruby-daemons/">Mike Perham</a>:</p> <blockquote> <p>...And since MRI never gives back unused memory, our daemon can easily be taking 300-400MB when it’s only using 100-200.</p> <p>It’s important to note that this is essentially by design. Ruby’s history is mostly as a command line tool for text processing and therefore it values quick startup and a small memory footprint. It was not designed for long-running daemon/server processes. Java makes a similar tradeoff in its client and server VMs.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload