2008/07/08

Release memory when using SqlAlchemy for a long time contextual session

First
session.flush()
then
session.close()

The close() method issues a clear(), and releases any transactional/connection resources. When connections are returned to the connection pool, whatever transactional state exists is rolled back.

When close() is called, the Session is in the same state as when it was first created, and is safe to be used again. close() is especially important when using a contextual session, which remains in memory after usage. By issuing close(), the session will be clean for the next request that makes use of it.

No comments: