<?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: Tag nested</title>
    <link>http://www.movesonrails.com/articles/tag/nested?tag=nested</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>
  </channel>
</rss>
