title: Memory leak with large dataset when using mysql-python
body: <p>I am experiencing what I believe is a memory leak when using the MySQLdb API</p>
  
  <pre><code>Line #    Mem usage    Increment   Line Contents
  ================================================
       6                             @profile
       7    10.102 MB     0.000 MB   def main():
       8    10.105 MB     0.004 MB       connection = MySQLdb.connect(host="localhost", db="mydb",
       9    11.285 MB     1.180 MB                                    user="notroot", passwd="Admin123", use_unicode=True)
      10    11.285 MB     0.000 MB       cursor = connection.cursor(cursorclass=MySQLdb.cursors.SSCursor)
      11                                 
      12    11.289 MB     0.004 MB       cursor.execute("select * from a big table;")
      13                                 
      14   254.078 MB   242.789 MB       results = [result for result in cursor]
      15   251.672 MB    -2.406 MB       del results
      16   251.672 MB     0.000 MB       return
  </code></pre>
  
  <p>Also when exploring the heap with <code>guppy</code>/<code>hpy</code> it shows that most of my memory is occupied by unicode objects, ints and datetime objects (very likely to be to rows return by the MySQLdb API).</p>
  
  <p>I'm using Python 2.7.3, <code>mysql-python==1.2.4</code> on Ubuntu 12.04 and profiled with <code>memory_profiler</code>.</p>
  
  <p>Could this be interning as described in <a href="http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm" rel="nofollow noreferrer">http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm</a> ?</p>
  
  <p>Am I missing any references dangling around?</p>
  
  <p><strong>EDIT:</strong> I also closed the cursor and connection but still got similar results.</p>
  
  <p><strong>SOLVED:</strong>
  Facepalm. I was doing a list comprehension with naturally kept everything in memory. When consuming the iterator properly (streaming to a file or something) it has decent memory usage.</p>
  
  <pre><code>Line #    Mem usage    Increment   Line Contents
  ================================================
      16                             @profile
      17    10.055 MB     0.000 MB   def main():
      18    10.059 MB     0.004 MB       connection = MySQLdb.connect(host="localhost", db="mydb",
      19    11.242 MB     1.184 MB                                    user="notroot", passwd="Admin123", use_unicode=True)
      20    11.242 MB     0.000 MB       cursor = connection.cursor(cursorclass=MySQLdb.cursors.SSCursor)
      21                                 
      22    11.246 MB     0.004 MB       cursor.execute("select * from big table")
      23    11.246 MB     0.000 MB       count = 0
      24    30.887 MB    19.641 MB       for result in cursor:
      25    30.887 MB     0.000 MB           count = count + 1
      26    30.895 MB     0.008 MB       cursor.close()
      27    30.898 MB     0.004 MB       connection.close()
      28    30.898 MB     0.000 MB       return
  </code></pre>