[mod_python] memory error

Mike Looijmans nlv11281 at natlab.research.philips.com
Fri Sep 28 07:00:03 EDT 2007

If Python does not release memory immediately, it usually means there's a cyclic reference. Try to 
break the cycle by removing as much references as possible.


a = A()
b = B()

a.b = b
b.a = b

Causes a "cycle". The garbage collector will pick these up at some other time.
To release earlier, assign None or delete the reference like:
a.b = None
or even:
del a.b

It usually helps to monitor big objects by putting a "print" statement in their __init__ and __del__ 

Mike Looijmans
Philips Natlab / Topic Automation

Webb Sprague wrote:
> Could anyone recommend a method for profiling memory usage in a
> mod_python application?
> My application creates lots and lots of scipy matrices, and then
> pickles them, and then stores them in a database.  If I do too many
> runs I get a memory error when I try to insert them, but I also get
> lots of swapping before that.  I could delete some of these arrays,
> but I would like to figure out where the biggest problems are (because
> I would prefer to store everything).
> I would be happy to analyze a core dump too.

More information about the Mod_python mailing list