https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112018-12-03T03:43:06ZRuby Issue Tracking SystemRuby master - Bug #15370: Array#=== in long running loop continually consumes more RAMhttps://redmine.ruby-lang.org/issues/15370?journal_id=753572018-12-03T03:43:06Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p><code>Array#===</code> is not <code>Array#member?</code>.<br>
<code>freq</code> is an <code>Array</code> and <code>sum</code> is an <code>Integer</code>, so<code>freq === sum</code> always returns <code>false</code> then <code>cycle</code> loops and <code>freq << sum</code> repeats forever.</p> Ruby master - Bug #15370: Array#=== in long running loop continually consumes more RAMhttps://redmine.ruby-lang.org/issues/15370?journal_id=753582018-12-03T03:45:22Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p><code>Array#===</code> is irrelevant. Your code executes <code>freq << sum</code> which extends the array and consumes the memory infinitely, even if you use <code>Array#member?</code>. The difference is that <code>Array#===</code> is much faster than <code>Array#member?</code>. Thus, the memory consumption is also faster.</p>
<p>Note that <code>Array#===</code> is not equal to <code>Array#member?</code>. In fact, <code>Array</code> has no <code>===</code> method. It is <code>Object#===</code> which is equal to <code>Object#==</code> by default.</p>
<pre><code>p [1,2,3] == 2 #=> false
p [1,2,3] == [1,2,3] #=> true
</code></pre> Ruby master - Bug #15370: Array#=== in long running loop continually consumes more RAMhttps://redmine.ruby-lang.org/issues/15370?journal_id=753632018-12-03T04:40:45Zdanielpclark (Daniel P. Clark)6ftdan@gmail.com
<ul></ul><p>Thanks both of you! :-) I saw some bad advice on StackOverflow and new that <code>case</code> worked as follows:</p>
<pre><code>case 2
when *[1,2,3]
puts :winner
end
# => winner
</code></pre>
<p>So I had assumed it would work. My mistake.</p>