Skip to content

Memory leaks in free-threaded build at shutdown #122697

Closed
@colesbury

Description

@colesbury

Bug report

The -X showrefcount isn't reporting leaked blocks on exit and we're hiding some leaked objects on shutdown. Note that we're still able to catch most leaks via the refleaks test.

-X showrefcount

_Py_GetGlobalAllocatedBlocks() is returning zero because the main interpreter is already NULL. This works in the default build because we've stashed away the number of leaked blocks in _PyRuntime.obmalloc.interpreter_leaks. We should do the same thing in the free-threaded build by updating _PyInterpreterState_FinalizeAllocatedBlocks().

Leaked objects on exit

Some objects that are referenced by global modules and use deferred reference counting are leaked on exit. Objects that use deferred reference counting are only collected by the GC. However, these object still have valid, live references when we run the GC for the final time. For example, one leaked object is a member_descriptor whose last reference is removed in clear_static_type_objects.

I think we'll cause too many problems if we try to invoke the GC later. Instead, I think that the free-threaded GC should disable deferred reference counting on all objects when its invoked for the final time.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions