I tried strong referencing the objects stored in the session using : def strong_reference_session(session): @event.listens_for(session, "pending_to_persistent") @event.listens_for(session, "deleted_to_persistent") @event.listens_for(session, "detached_to_persistent") @event.listens_for(session, "loaded_as_persistent") def strong_ref_object(sess, instance): if 'refs' not in sess.info: sess.info['refs'] = refs = set() else: refs = sess.info['refs']
refs.add(instance) as specified in the docs. Still, I have no way to get control over my object, and in the example I sent you I stay in the same scope, so session shouldn't lose reference to the object anyhow. Moreover, in this example, I am just requesting the object, I don't make any modifications on it, yet I can't flush, expire or expunge it, and finally, the session.close() don't free the memory. I don't get why in the simple example I sent you I can't flush my object. If i was to loop over this function, my memory would grow infinitely, and that's precisely what's happening when my script is running. -- 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/99190797-eeb3-4ca1-9fd4-adde124ae3b5%40googlegroups.com.