Hi,
How significant is the memory growth? Some actual numbers would help.
Does calling gc.collect() help?
Does removing the __del__ methods and then calling gc.collect() help?
Do you see a constant increase in len(gc.get_objects())? It could be
just memory fragmentation.
> I think the important part is that the view is a "class" and it stores
> the request as class attribute. And in fact with a few modifications
> to store the request as a weakref attribute (class ViewWeakref) the
> application works allright and everything gets cleaned up.
I see no class attributes in your code, only instance attributes.
The fact that using a weakref helps is a hint that there's normally a
reference cycle, which means reference counting isn't going to free the
objects normally, and you have to wait for the next scheduled garbage
collection to happen (or call gc.collect() explicitly) for objects to be
freed.
Note that the amount of memory used by the Python process is unlikely to
go down, due to memory fragmentation.
Also note that Python cannot free objects participating in a reference
cycle if they have __del__ methods on objects.
> Now, I don't think this happens every time a view class is involved.
> My original application for example stores the request as view class
> atrribute (without using weakref) and works allright. But I suppose
> there are a few rare cases depending on how views are invoked by
> pyramid making it easy to run into leaking applications.
I wrote
http://pypi.python.org/pypi/objgraph when I was debugging a
memory leak in an app's test suite. It may help you narrow down the
leak, if there is one.
Marius Gedminas
--
To express oneself
In seventeen syllables
Is very diffic
-- John Cooper Clark.