This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation about Py_Finalize(): Freeing objects
Type: Stage:
Components: Documentation, Interpreter Core Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Albert.Zeyer, docs@python, iritkatriel, vstinner
Priority: normal Keywords:

Created on 2015-01-21 17:53 by Albert.Zeyer, last changed 2022-04-11 14:58 by admin.

Messages (1)
msg234441 - (view) Author: Albert Zeyer (Albert.Zeyer) * Date: 2015-01-21 17:53
The documentation about Py_Finalize() about freeing objects is not exactly clear.

Esp., when I have called Py_INCREF somewhere, those objects will always have ob_refcnt > 0 unless I call Py_DECREF somewhere, what about these objects? Will they be freed in Py_Finalize() or not? If not, what can I do? I guess calling Py_DECREF after Py_Finalize() is not allowed.

I studied the Py_Finalize() code but I'm not exactly sure. It looks like such objects would not get freed (unless some implicit magic is happening somewhere). The comment about the last commented-out PyGC_Collect() call is also insightful and somewhat unsatisfying.

Maybe PyObject_Free() still works, although that would not free any further referenced objects, I guess. Also, I'm not exactly sure about the pymalloc arenas.

With pymalloc, maybe we could just free all pymalloc arenas and it would free all memory allocated by Python objects? Of course, that would not call any advanced tp_dealloc functions which might be important to be called, but we would never ever call those anyway anymore, or would we (how?)?
So, maybe it would be good to do that?
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67480
2022-01-28 19:43:34iritkatrielsetnosy: + iritkatriel, docs@python, vstinner

assignee: docs@python
components: + Documentation
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7
2015-01-21 17:53:44Albert.Zeyercreate