On Thu, Mar 5, 2020, at 5:17 AM, Adrien Blin wrote: > > > I'll try to recreate the issue for you to test it, but my question really is > : Is there something I didn't get about memory usage in sqlalchemy, meaning, > is it normal for it to retain objects in memory, and if so, how can we get > past it ?
no, it's not normal. The ORM Session tracks your objects using Python weak references so that if your own application loses references to those objects, the Session will also. If the objects have pending changes on them, meaning you altered the state of one or more of the mapped attributes, the Session will temporarily link to that object strongly, meaning it won't be immediately garbage collectable, until the next flush proceeds. So if you have turned off autoflush, are reading a large number of objects, modifying them all such that they have pending, flushable changes on them, and then never flushing or committing or otherwise closing / deleting that Session object, that will grow memory. otherwise no. Additionally, if you run the Python interpreter without garbage collection running, that will grow memory also as the gc collector is necessary in order to collect unreachable cycles. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/be105ac2-e0e0-4057-a0aa-fe071adf3e6d%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/be105ac2-e0e0-4057-a0aa-fe071adf3e6d%40googlegroups.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/8e751da8-ff1d-489a-8c1c-997bf4549a2a%40www.fastmail.com.