<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Moves On Rails: Nested include has major memory leak (Rails 2.0.1).</title>
    <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>New ways to look at software</description>
    <item>
      <title>Nested include has major memory leak (Rails 2.0.1).</title>
      <description>&lt;p&gt;As our mongrels were using up quite a lot of memory, so I tried to figure out what was causing this.&lt;/p&gt;

&lt;p&gt;When running the app locally I found out that one certain page caused the mongrel to grow from 60 to 190 megabytes. A whopping 130 megabytes!&lt;/p&gt;

&lt;p&gt;After commenting out some of the code, I realized that a single line was causing all of the memory usage &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;contracts = Contract.find( :all, 
  :conditions =&amp;gt; ['contracts.employee_id IN (?) ', employees ],
  :include =&amp;gt; [:expertise_profile =&amp;gt; :qualifications ] )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ouch! The nested include of rails somehow leaks a large amount of memory.
The fix was a piece of cake.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;contracts = Contract.find( :all, 
  :conditions =&amp;gt; ['contracts.employee_id IN (?) ', employees ],
  :include =&amp;gt; :expertise_profile )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now my mongrel stays at 60 megabytes. I don't know if this issue persists in the new 2.1 Rails, but I'll check that soon!&lt;/p&gt;</description>
      <pubDate>Wed, 02 Jul 2008 15:59:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1a3ee134-137c-49b9-9d0d-9d868a301f41</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1</link>
      <category>Rails</category>
      <category>find</category>
      <category>nested</category>
      <category>include</category>
      <category>memory</category>
      <category>rails</category>
    </item>
    <item>
      <title>"Nested include has major memory leak (Rails 2.0.1)." by Matt Griffith</title>
      <description>Thanks for posting this. I'm seeing the same thing even when using a non-nested :include. I have an :include that loads 6 associations and it has a similar leak. This is in 2.0.2, I haven't tested 2.1 yet. </description>
      <pubDate>Fri, 15 Aug 2008 04:27:35 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:c4450aad-c9e8-4f08-9ad1-b02343faf0ca</guid>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1#comment-294</link>
    </item>
    <item>
      <title>"Nested include has major memory leak (Rails 2.0.1)." by Bart ten Brinke</title>
      <description>You are correct Steve, but normally after a request, the mongrel should return to its normal memory footprint, which in this case it does not. The footprint grew 130 MB which is only returned when you restart the mongrel.</description>
      <pubDate>Fri, 15 Aug 2008 00:08:24 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:125bcf6a-cbe6-4601-b47c-4c5ce238c65d</guid>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1#comment-293</link>
    </item>
    <item>
      <title>"Nested include has major memory leak (Rails 2.0.1)." by Steve Root</title>
      <description>I'm new to rails, but isn't the difference here that you are no longer (eager) loading the qualifications table into the model? 

The less data you load, the smaller the memory used</description>
      <pubDate>Tue, 05 Aug 2008 17:07:14 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:bb1e18b8-cd55-4430-af8d-73493addedd9</guid>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1#comment-289</link>
    </item>
    <item>
      <title>"Nested include has major memory leak (Rails 2.0.1)." by Jon Dahl</title>
      <description>Great catch. Be sure to post again if you find out anything more (like: if 2.1 has the same problem, or the underlying cause of the leak).</description>
      <pubDate>Wed, 02 Jul 2008 17:21:11 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:26a2d3e5-e757-4cf6-a6ae-04b5875d813e</guid>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1#comment-286</link>
    </item>
  </channel>
</rss>
