Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed as not planned
Description
Bug report
Bug description:
Since67807cf,_testembed.exe (x64 Release) increases the memory usage in the cycle ofPy_Initialize andPy_Finalize.
I monitored the Task Manager (taskmgr.exe) on Windows10/11, with a change againstPrograms/_testembed.c:
-#defineINIT_LOOPS 4+#defineINIT_LOOPS 200
Commands:
_testembed.exe test_repeated_simple_initorpython -m test test_embed -m test_simple_initialization_api(no log)
With RADIX TREE (as-is)
| Loop | 67807cf | main | 3.11.7 |
|---|---|---|---|
| 100 | 67MB | 210MB | 4MB |
| 200 | 135MB | 406MB | 4MB |
No RADIX TREE (as-is)
| Loop | 67807cf | main | 3.11.7 |
|---|---|---|---|
| 100 | 10MB | 168MB | 4MB |
| 200 | 16MB | 336MB | 4MB |
Recentobmalloc.c looks ready for finalization. Just adding my rough (invalid?) experiment made the leaks even. So, I hope that they share the same issue. Otherwise,ea2c001 or15d4c9f has another leak.#98359 (comment)
patch
void_PyInterpreterState_FinalizeAllocatedBlocks(PyInterpreterState*interp){if (has_own_state(interp)) {Py_ssize_tleaked=_PyInterpreterState_GetAllocatedBlocks(interp);assert(has_own_state(interp)||leaked==0);interp->runtime->obmalloc.interpreter_leaks+=leaked;+OMState*state=&interp->obmalloc;+for (uinti=0;i<maxarenas;++i) {+if (allarenas[i].address==0) {+continue;+ }+_PyObject_Arena.free(_PyObject_Arena.ctx,+ (void*)allarenas[i].address,ARENA_SIZE);+allarenas[i].address=0;+--narenas_currently_allocated;+ }+PyMem_RawFree(allarenas); }}
With RADIX TREE (patched)
| Loop | 67807cf | main |
|---|---|---|
| 100 | 42MB | 40MB |
| 200 | 80MB | 80MB |
No RADIX TREE (patched)
| Loop | 67807cf | main |
|---|---|---|
| 100 | 3.5M | 3.3M |
| 200 | 3.7M | 3.4M |
CPython versions tested on:
3.12, 3.13, CPython main branch:3aea6c4
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done