Python C Extensions

aken8062 at aken8062 at
Thu Feb 24 11:01:40 EST 2011


I have a memory leak problem with my "C" extension module. My C module
returns large dictionaries to python, and the dictionaries never get
deleted, so the memory for my program keeps growing.

I do not know how to delete the dictionary object after it becomes
irrelevant. I do not know if the version of python is relevant, I'm
using the 2.5 !

Here is the "C" code:

PyObject *GetDictionary(PyObject *self, PyObject *args)
  PyObject *dict = PyDict_New();
  PyObject *key;
  PyObject *value;

  char name[128];

  for(int i = 0; i < 60; i++)
      float number = 1.0 * 0.5*i;
  return dict;

And here is the Code that I use in a loop, which causes the program
memory to grow:
import libpyTestModule as pyTEST

bankTEST = {}
for j in range(1,100000):
    for k in range(1,100000):
        bankTEST = pyTEST.GetDictionary()
        del bankTEST

Any help will be appreciated.

More information about the Python-list mailing list