-- Bugfix #3186: Fix memory leaks caused by multiple calls to

PyDict_SetItemString() with objects that were not properly decrefed
   afterwards.  Due to the number of places this was used, I added a
   wrapper EXPP_dict_set_item_str() to gen_utils.c to handle it.

   This started as a scriptlink bug, due to how many times scripts were
   being executed I think it just magnified how bad the memory leak in
   BPy was.  Animating the blend attached with this bug report would cause
   memory to grow by about 3MB for every 280 frames.  After the patch,
   memory did not appear to grow at all (or at least not noticably using
   Unix's ps and top utils).

   Since many of the PyDict_SetItemString() calls were in initialization
   modules I think my tests executed most of the changed code, but would
   appreciate script users really giving feedback.
This commit is contained in:
Ken Hughes
2005-11-30 08:18:06 +00:00
parent 00f4310970
commit b7a4a6c837
11 changed files with 60 additions and 47 deletions

View File

@@ -904,3 +904,16 @@ PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args,
return NULL;
}
/*
* Helper to keep dictionaries from causing memory leaks. When some object
* is just created to be added to the dictionary, its reference count needs
* to be decremented so it can be reclaimed.
*/
int EXPP_dict_set_item_str( PyObject *dict, char *key, PyObject *value)
{
/* add value to dictionary */
int ret = PyDict_SetItemString(dict, key, value);
Py_DECREF( value ); /* delete original */
return ret;
}