Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you are entering <em>The Lost World</em> here. I don’t think the problem is with c-bindings in <code>racc</code> either.</p> <p>Ruby memory management is both elegant and cumbersome. It stores objects (named <code>RVALUE</code>s) in so-called <em>heaps</em> of size of approx 16KB. On a low level, <code>RVALUE</code> is a c-struct, containing a <code>union</code> of different standard ruby object representations.</p> <p>So, heaps store <code>RVALUE</code> objects, which size is not more than 40 bytes. For such objects as <code>String</code>, <code>Array</code>, <code>Hash</code> etc. this means that small objects can fit in the heap, but as soon as they reach a threshold, an extra memory outside of the Ruby heaps will be allocated.</p> <p><strong>This extra memory is flexible; is will be freed as soon as an object became GC’ed.</strong> That’s why your testcase with <code>big_string</code> shows the memory up-down behaviour:</p> <pre><code>def report puts 'Memory ' + `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"` .strip.split.map(&amp;:to_i)[1].to_s + 'KB' end report big_var = " " * 10000000 report big_var = nil report ObjectSpace.garbage_collect sleep 1 report # ⇒ Memory 11788KB # ⇒ Memory 65188KB # ⇒ Memory 65188KB # ⇒ Memory 11788KB </code></pre> <p>But the heaps (see <code>GC[:heap_length]</code>) themselves <strong>are not released</strong> back to OS, once acquired. Look, I’ll make a humdrum change to your testcase:</p> <pre><code>- big_var = " " * 10000000 + big_var = 1_000_000.times.map(&amp;:to_s) </code></pre> <p>And, voilá:</p> <pre><code># ⇒ Memory 11788KB # ⇒ Memory 65188KB # ⇒ Memory 65188KB # ⇒ Memory 57448KB </code></pre> <p>The memory is not released back to OS anymore, because each element of the array I introduced <em>suits</em> the <code>RVALUE</code> size and <em>is stored</em> in the ruby heap.</p> <p>If you’ll examine the output of <code>GC.stat</code> after the GC was run, you’ll find that <code>GC[:heap_used]</code> value is decreased as expected. Ruby now has a lot of empty heaps, ready.</p> <p><strong>The summing up:</strong> I don’t think, the <code>c</code> code leaks. I think the problem is within base64 representation of huge image in your <code>css</code>. I have no clue, what’s happening inside parser, but it looks like the huge string forces the ruby heap count to increase.</p> <p>Hope it helps. </p>
 

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