1

I have developed a complex program in which a thread pool execute tasks planned by many objects. I have memory leaks.

So far I have detected using guppy that the number of created objects is growing steadily, but they are not destroyed. How can I know what objects are not destroyed/collected?

Here is an excerpt of my code:

# Memory Profiling
from guppy import hpy
import gc

class ThreadPool:
    ...
    # Every 1 sec run:
    gc.collect() # yes, this is paranoid...
    print str(self.h.heap()).split('\n')[0]

And the result is:

Partition of a set of 110304 objects. Total size = 15475848 bytes.
Partition of a set of 110318 objects. Total size = 15479920 bytes.
Partition of a set of 110320 objects. Total size = 15480808 bytes.
Partition of a set of 110328 objects. Total size = 15481408 bytes.
...

What were the last objects created? Is there some introspection code that can help?

Thank you!

The Dare Guy
  • 487
  • 1
  • 3
  • 12
  • What version of python? (python --version) – jjm Aug 05 '13 at 22:59
  • I am using python version 2.7.3 – The Dare Guy Aug 05 '13 at 23:02
  • There's no way to tell the last objects created, except to track them yourself. If the `gc` module doesn't give you enough to track what's going on, you will have to do it at the application level. – abarnert Aug 05 '13 at 23:04
  • Am I right in understanding that what you want is to see a list of objects created since the last time you inspected the heap (or whatever you want to call what you're doing each second in the code you posted)? – jjm Aug 05 '13 at 23:15
  • Yes, jjm, you are right. In fact, what I want is to solve the memory leaks... – The Dare Guy Aug 05 '13 at 23:30
  • Check out http://stackoverflow.com/questions/1435415/python-memory-leaks – dstromberg Aug 06 '13 at 00:18
  • Also http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended – jjm Aug 06 '13 at 00:33

0 Answers0