title: How do I track down a memory leak in my Ruby code?
body: <h2>Question</h2>
  
  <p>I'm debugging a memory leak in a rake task. I want to see a call stack of:</p>
  
  <ul>
  <li>Living objects</li>
  <li>What object or line originally allocated those objects</li>
  </ul>
  
  <p>Is this possible with ruby-prof?</p>
  
  <p>If not, what tool should I use? </p>
  
  <h2>Setup</h2>
  
  <p><strong>Gems</strong></p>
  
  <ul>
  <li>rails 3.2.16</li>
  <li>event_bus 1.0.0 (<a href="https://github.com/kevinrutherford/event_bus">https://github.com/kevinrutherford/event_bus</a>)</li>
  <li>activerecord-fast-import (<a href="https://github.com/jsuchal/activerecord-fast-import">https://github.com/jsuchal/activerecord-fast-import</a>)</li>
  </ul>
  
  <p><strong>Rake task</strong></p>
  
  <ul>
  <li>Imports a CSV file directly into a MySql database using DATA LOAD INFILE and Active Record objects.</li>
  </ul>
  
  <h2>What I've Tried</h2>
  
  <p>I've tried the modes</p>
  
  <ul>
  <li>RubyProf::ALLOCATIONS</li>
  <li>RubyProf::MEMORY</li>
  </ul>
  
  <p>All it says in the documentation is:</p>
  
  <p>RubyProf::ALLOCATIONS
  Object allocation reports show how many objects each method in a program allocates.</p>
  
  <p>RubyProf::MEMORY
  Memory usage reports show how much memory each method in a program uses.</p>
  
  <p>This implies that ruby-prof just reports on the total allocation of objects, not just the ones that are living.</p>
  
  <p>I've tried <a href="https://github.com/archan937/ruby-mass">Ruby-Mass</a> and <a href="https://github.com/ronen/bloat_check">Bloat Check</a> but neither seem to be able to do what I want. Ruby-Mass also crashes because it's finding FactoryGirl objects in memory for some reason...</p>