Session and SessionTransaction holding references to each other causes memory leak
Issue #2414
resolved
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)
-
repo owner -
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.
-
repo owner so.... "worksforme" or are you still observing an issue due to this cycle?
-
repo owner - changed status to wontfix
Reopen this ticket if you find a memory leak within SQLA.
- Log in to comment
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 ?