Memory leak: assigning function object to instance variable

John Parkey jparkey at nospamrapidbs.com
Mon Jun 5 15:55:59 EDT 2000


I have registered this bug, with code fragment below, but wondered if
anybody else was falling foul of memory leaks of this type.  We use xmllib,
which relies on assigning methods to instance variables for later callbacks.
Our recent volume testing has shown serious leakage relating to this problem
(I use it in other places too, so it's pretty serious for us).  Environment
is 1.5.2 on NT, build 132.  To see the problem, run the example below and
watch memory usage in task manager.

(Quick plug for Mark Hammond - thanks for loads of help, and finding/fixing
COM related leaks). I hope my week of leak hell will soon be over!

class fred:
 def __init__(self):
  self.indirectFunc = self.theFunc

 def theFunc(self):
  return "blah"

def test():
 f = fred()
 del f

if __name__ == "__main__":
 for x in xrange(1000):
  test()






More information about the Python-list mailing list