← Winnitude! Search  ·  Reader Mode (944 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 7 LINKS

Memory not released upon multiple Initialize/Shutdown · Issue #2594 · pythonnet/pythonnet

Repository navigation

Memory not released upon multiple Initialize/Shutdown  #2594


New issue

New issue

Open

Open
Memory not released upon multiple Initialize/Shutdown #2594

Description

@Ledragon's profile Ledragon opened on May 19, 2025

Exectuing the following code in a basic Console app leads to the application consuming more and more memory:

            Runtime.Runtime.PythonDLL = @"C:\ProgramData\WideTech\Python\python38.dll";
            PythonEngine.PythonHome = @"C:\ProgramData\WideTech\Python\";
            var count = 1000;
            for (int i = 0; i < count; i++)
            {
                PythonEngine.Initialize();
                PythonEngine.Shutdown();
            }

I am on windows 11 (64bit), using PythonNet v3.0.5, combined with Python 3.8 (happens with Python 3.12 as well).

For more context, we have a WebAPI that runs python 3 code that interacts with C# code. I tried avoiding initalization and shutdown systematically, but then I encounter API crashes. While current implementation might not be perfect (especially given 2008 - that we are facing as well, but is not the topic), it works, besides the increasing memory consumption.

Am I missing anything regarding resources freeing?

Reacted by Maciej Sobkowiak

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions