Session and SessionTransaction holding references to each other causes memory leak

Issue #2414 resolved
Andrey Popp created an issue

Using objgraph library I've found a memory leak — Session holds ref to SessionTransaction and vice-versa. See attached image. Setting session.transaction to None in session.close() will help this.

Comments (4)

  1. Mike Bayer repo owner

    A reference cycle isn't the same thing as a leak, as Python's gc collects unreachable reference cycles. Are you trying to run without gc enabled ? There's plenty of reference cycles in SQLAlchemy, they're quite necessary. We have a series of tests in test/aaa_profiling/test_memusage.py that are pretty exhaustive about testing any kind of unbounded memory growth, provided gc is running normally.

    Unless the issue is you'd just like the Session to be collected immediately ?

  2. Andrey Popp reporter

    Hm... somehow I have this growing. Maybe it's related to my setup — I'm holding SA session in thread local, but that shouldn't be a problem there because objgraph doesn't report any other pointers to session.

  3. Log in to comment