Rails Memory leak using highChart with a lot of data
<p>I hava a highchart graphic in one of my views and an option to select a a range of dates to query and show in the graphic. The think is when I perform a query with a big date range (e.g. a year range), the memory goes up and it never goes back to a normal state and finally I need to reset the server...
The view calls a class method that performs the query and return the array of data to create the graphic. The method initially was this:</p>

<pre><code>data = []

  messages.each do |message|
    record = []
    record &lt;&lt; message.occurance_time.to_s(:highcharts_format)
    record &lt;&lt; weight_according_to_metric(message.weight, us_metric_enabled)
    record &lt;&lt; temperature_according_to_metric(message.temperature, us_metric_enabled)
    record &lt;&lt; (message.humidity.nil? ? nil : message.humidity.to_f)
    data &lt;&lt; record
  end
</code></pre>

<p>but after some tests I put <em>find_each</em> instead of <em>.each</em> and I wrapped the loop inside a <strong>ActiveRecord::Base.uncached</strong> statment:</p>

<pre><code>data = []
ActiveRecord::Base.uncached do
  messages.find_each do |message|
    record = []
    record &lt;&lt; message.occurance_time.to_s(:highcharts_format)
    record &lt;&lt; weight_according_to_metric(message.weight, us_metric_enabled)
    record &lt;&lt; temperature_according_to_metric(message.temperature, us_metric_enabled)
    record &lt;&lt; (message.humidity.nil? ? nil : message.humidity.to_f)
    data &lt;&lt; record
  end
end
</code></pre>

<p>But I'm still having memory issues. It is obvious that while the queries are being executed the memory goes up, but why is not the memory going down after the query and graphic creation?</p>

<p>It's running with puma on Heroku!</p>

<p>Any thoughts?</p>