title: Why is this python script slowly chewing up my RAM?
body: <p>This script slowly eats my RAM.  When I run it, I can see the RAM usage of Python creep up by approx 1mb with each loop, but I can't figure out why.  I have figured out that it is the iteration of the query that adds the RAM, but that's all I can figure out.  Any help would be awesome.</p>
  
  <pre><code>from haystack.pmod import piliPlacement #this is the SA model
  from time import sleep
  from datetime import datetime
  from sqlalchemy import create_engine
  from sqlalchemy.orm import sessionmaker
  
  
  now = datetime.now()
  
  
  engine = create_engine('mssql://xxxxxxx;uid=user;pwd=xxxxx',echo=False)
  
  
  Session = sessionmaker(bind=engine)
  
  
  def syncPlacements(session):
      query = session.query(piliPlacement).filter(piliPlacement.Time &gt; now)
      pili_placements = [p.ID_Placement for p in query.all()] # this is what adds the RAM
      del pili_placements
      print 'loop'
  
  
  while True:
      session = Session()
      syncPlacements(session)
      sleep(3)
  </code></pre>