lgx schrieb:
> Does PyDict_SetItemString(pDict,"key",PyString_FromString("value"))
> cause memory leak?
> 
>>From Google results, I find some source code write like that. But some
> code write like below:
> 
> obj =  PyString_FromString("value");
> PyDict_SetItemString(pDict,"key",obj);
> Py_DECREF(obj);

Sorry, my previous response came from the completely wrong bag.

The second is right. PyString_FromString() increases the refcount of the
returned string, so you have to decref it after use.

PyDict_SetItemString() does its own refcount increase internally when it
stores the value, so don't bother about it at all when you think about what
refcounts you have to increase or decrease.

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to