A
aken8062
Hi,
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++)
{
sprintf(name,"v%d",i);
float number = 1.0 * 0.5*i;
PyDict_SetItem(dict,Py_BuildValue("s",name),Py_BuildValue("f",number));
}
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.
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++)
{
sprintf(name,"v%d",i);
float number = 1.0 * 0.5*i;
PyDict_SetItem(dict,Py_BuildValue("s",name),Py_BuildValue("f",number));
}
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.