opentk / GLControl

WinForms control for OpenTK 4.x.
https://opentk.net
Other
54 stars 24 forks source link

Memory Leak when Resizing GLControl #17

Closed langelo1 closed 2 years ago

langelo1 commented 2 years ago

I'm experiencing a severe memory leak when resizing a GLControl that is docked inside the parent form. This occurs when running the demo project OpenTK.WinForms.TestForm.csproj included in the latest OpenTK 4.x WinForms library. I first noticed this issue in my own project that I created from scratch following the examples provided in TestForm.csproj.

To reproduce this issue:

  1. Download the latest GLControl library
  2. Open the OpenTK.WinForms.TestForm.csproj
  3. Ensure there is a GLControl added inside the form
  4. In the Layout Properties for the GLControl, set the Dock property to "Fill"
  5. Run the program and then resize the window that the GLControl is docked in

Things that might be of interest:

  1. Using Visual Studio 2019, Windows10 64-bit
  2. Using OpenTK 4.6.7
  3. No discrete graphics card; I'm using Intel's integrated graphics (11700K)
  4. This issue does not occur when running OpenTK outside of WinForms
  5. Occurs when using the Nuget Package as well as compiling the code into a DLL myself
  6. I am a beginner in programming C#
langelo1 commented 2 years ago

I discovered that the "memory leak" does not occur when the GLControl Profile is set to "Compatibility" mode instead of the default "Core" mode. Also, the APIVersion property must be set to 3.3.0.0. During troubleshooting I had set the APIVersion to 4.6.0.0.

Also, I don't know if the problem was actually a memory leak, or just a lack of garbage collection. Again, I'm a beginner, so take what I say with a grain of salt.

NogginBops commented 2 years ago

What kind of leak where you seeing? How much memory was allocated and where did you see that number (Visual studio, task manager, etc)? @seanofw you know more about the specifics of the implementation here but I don't see the logic behind Compatibility vs Core effecting this but maybe you could do a sanity check and see if you also get the leak?

langelo1 commented 2 years ago

I observed the leak in the Process Memory tracker in Visual Studio. The process memory spiked rapidly while resizing the window. The increase in process memory was proportional to the size of the window being resized. Resizing the window while close to its maximum size caused the process memory to exceed 3GB in about 10 seconds which caused the program to crash.

Today I was able to run the same app on a computer with a discrete graphics card and the leak did not occur even with the GLControl set to “core” mode.

seanofw commented 2 years ago

I haven't been able to reproduce this, but I don't have anything to test on that has an integrated Intel graphics card either. Intel's drivers are known to have bugs; if I had to bet on anything, I'd bet that the memory is being leaked outside of .NET by Intel's drivers.

seanofw commented 2 years ago

@langelo1 Do you have any further information on this? Nine months later, I'm inclined to close this issue as "can't reproduce."