On Nov 7, 2008, at 6:21 AM, joelanman wrote:

>
> Hi,
>
> I'm getting a memory leak with my app - the stack is apache2,
> mod_wsgi, web.py - and then a lot of sqlalchemy and my own code. The
> issue may well not be with my usage of SQLA - just making sure there's
> nothing I might be doing wrong with it.
>
> At the start of every web request (__init__ for a controller) I open a
> Session(), and in __del__ I close() it. Is there anything else I ought
> to do?

that is the correct procedure.  The Session weak references everything  
anyway so its hard for it to cause a fast leak.

> Any pointers on how to chase down my memory problem?

one way is to visually inspect your application for any global  
variables, like dictionaries, caches, etc. and to analyze if they grow  
arbitrarily.   Anything that is global or held across requests is  
suspect and should be analyzed carefully.   Also, any usage of __del__  
should be carefully scrutinized, as a cyclical reference on an object  
that implements __del__ cannot be garbage collected (that you're using  
__del__ might be the issue here.   __del__ is actually never really  
needed as you can use a weakref callback for cleanup activities).

Some third party libraries can also cause "leaky" behavior, such as  
Beaker.   Try disabling any caching utilities to see if that isolates  
the issue.

The other way is to analyze leaks is to use gc facilities - such as  
peeking into gc.get_objects() to see what kinds of objects are growing  
the collection, or gc.set_debug(gc.DEBUG_LEAK) which deals with  
unreachable objects (i.e. because of __del__).    I usually opt for  
the former since I don't really use __del__ but I use global caches of  
things quite a bit.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to