Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspected memory leak when opening multiple instances of GameWindow in OpenTK 3.3.3 #1588

Open
henrysjl opened this issue May 2, 2023 · 0 comments

Comments

@henrysjl
Copy link

henrysjl commented May 2, 2023

Description

I've been working with an application which requires multiple GameWindow instances to be opened during runtime. It works well, except for unexpected memory leaks when old GameWindow instances are closed and disposed of. It seems as though every instance of GameWindow has a reference in OpenTK.Platform.Windows.WinFactory, and this is not disposed of even when every GameWindow is closed.

Repro steps

Step 1: Create a new instance of GameWindow during the runtime of an application (e.g. a Winform in this case)
Step 2: Close the GameWindow, and dispose of it.
Step 3: Repeat steps 1 and 2 multiple times, then take a memory snapshot. You'll find instances of GameWindow still alive, and still using memory.

Here's a code snippet which reproduces this problem:

for (int i = 0; i < 6; i++)
{
    GameWindow window = new GameWindow();
    using (window)
    {
        window.Run(60);
    }
    window.Dispose();
}
GC.WaitForPendingFinalizers();

Expected behavior

All memory released by GameWindow after it goes out of scope.

Actual behavior

Many instances of GameWindow are left in memory, causing a leak - this isn't too significant with empty GameWindows, but when these instances contain real data the memory piles up.
image

Related information

  • Operating system: Windows 10
  • Native backend
  • Nuget OpenTK 3.3.3
  • .NET Framework 4.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants