On Thu, Mar 5, 2020, at 10:17 AM, Adrien Blin wrote:
> 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. 

I'm sorry, what document is this? Are you referring just to how to use the 
events? Why are you trying to create strong references to objects if the goal 
here is to reduce memory use ?



> 
> 
> 
> 
> 
> 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.

Sorry, still not following here. I thought a memory leak was the issue.


> 
> 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.

Why can't you flush it? Is there some error message ? I am not following any of 
what you are trying to do.



> 

> --
>  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
>  
> <https://groups.google.com/d/msgid/sqlalchemy/99190797-eeb3-4ca1-9fd4-adde124ae3b5%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/f328ecb3-43b3-4fd5-affe-4f0ec79f9685%40www.fastmail.com.

Reply via email to