Garage Monitor Memory Leak: Part 2

Update: I may have found a solution. Read about it in Garage Monitor Memory Leak: Part 3

Note: While this was an interesting exercise, I don’t understand the results so I cannot use them to find the issues at this time. I think my next step will look up some Python Best Practices. I have already found an interesting discussion on Stack Overflow.

In an effort to trace the memory leak, I discovered an article. In the article Marek Majkowski describes using the Python Debugger (PDB), and a garbage collection library. His article also describes the use of Python Object Graphs, an open source library written by Marius Gedminas.

Installing Python Object Graphs

To get Python Object Graphs installed I had to preform the following steps.
1. Install pip.

sudo wget http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
tar xvfz pip-1.2.1.tar.gz
cd pip-1.2.1/
sudo python ./setup.py build
sudo python ./setup.py install

2. Install Python Object Graphs.

sudo pip install objgraph

3. Install Python Object Graphs recommended modules.

sudo pip install xdot
sudo pip install graphviz

Running Python Object Graphs

At this point I am just flailing about, but after changing into my project’s directory I run the following commands.
1. Run my python script in the Python Debugger (PDB).

sudo pdb garagemonitor.py

2. Execute the code for a while before a control-C

r
^C

3. Attempt to show what items are taking up more memory.

import objgraph
objgraph.show_growth()

Does anyone know what to do with these results? I can see the second time through the following items grew: wrapper_descriptor (+7), member_descriptor (+2), getset_descriptor (+2), weakref (+2), tuple (+1), traceback (+1), dict (+1).

(Pdb) import objgraph
(Pdb) objgraph.show_growth()
function                       1732     +1732
wrapper_descriptor             1074     +1074
builtin_function_or_method      722      +722
dict                            547      +547
tuple                           499      +499
method_descriptor               451      +451
weakref                         441      +441
list                            254      +254
member_descriptor               206      +206
type                            206      +206
(Pdb) r
(Pdb) objgraph.show_growth()
wrapper_descriptor     1081        +7
member_descriptor       208        +2
getset_descriptor       192        +2
weakref                 443        +2
tuple                   500        +1
traceback                 3        +1
dict                    548        +1

Leave a Reply