SQLA doesn't maintain strong references to anything at the module level. The objects you have above appear to be related to the "compiled cache" used by an individual mapper. This is an LRU-enabled dictionary that holds onto Insert constructs and their compiled form up to approximately 100 elements. The dictionary is associated with a mapper, which in turn is associated with your mapped class. If you dereference your mapped class (and all instances of that class), the mapper and the LRU cache will be gone. You can also say mapper._compiled_cache.clear() which will probably remove the Insert/SQLiteCompiler objects above.
As for Sessions, if you close(), commit(), rollback(), or expire_all() the session object, all user objects inside are weakly referenced by the session (though related objects will have strong references to each other).
>
> thanks
> Nicola
>
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
When we do memory tests we typically take an application loop we'd like to test and then run it about 50 times, counting the total size of gc, and we then look to make sure that gc isn't growing over time. A "sawtooth" pattern in gc growth is common - meaning gc grows for 6-10 iterations, then it goes down again. This is actually in some cases indpendent of calls to gc.collect(). Newer versions of Pysqlite for example have some internal references that are cleared out periodically which cause this symptom to appear. If you want to try our test fixture the profile function is at http://www.sqlalchemy.org/trac/browser/test/aaa_profiling/test_memusage.py#L32 .