Message 411075 - Python tracker

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.

Content
Using the C program below, I see that _Py_RefTotal is decreasing at each iteration:
---
#include <Python.h>
int main(int argc, char *argv[])
{
    for (int i=1; i <= 100; i++) {
        Py_SetProgramName(L"./_testembed");
        Py_Initialize();
        Py_Finalize();
        printf("Loop #%d: %zd refs\n", i, _Py_RefTotal);
    }
}
---

Example of output:
---
...
Loop #96: 9557 refs
Loop #97: 9544 refs
Loop #98: 9531 refs
Loop #99: 9518 refs
Loop #100: 9505 refs
---

It seems to be a regression caused by this change:

commit 1cbaa505d007e11c4a1f0d2073d72b6c02c7147c
Author: Guido van Rossum <guido@python.org>
Date:   Wed Nov 10 18:01:53 2021 -0800

    bpo-45696: Deep-freeze selected modules (GH-29118)
    
    This gains 10% or more in startup time for `python -c pass` on UNIX-ish systems.
    
    The Makefile.pre.in generating code builds on Eric's work for bpo-45020, but the .c file generator is new.
    
    Windows version TBD.


Before the change, _Py_RefTotal was stable: 
---
...
Loop #97: 10805 refs
Loop #98: 10805 refs
Loop #99: 10805 refs
Loop #100: 10805 refs
---

I found this issue while working on bpo-46417 which is related to bpo-1635741.