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

Memory leaks when using System.Windows.Forms #12096

Open
shashidhar-ks opened this issue Sep 10, 2024 · 1 comment
Open

Memory leaks when using System.Windows.Forms #12096

shashidhar-ks opened this issue Sep 10, 2024 · 1 comment
Labels
📭 waiting-author-feedback The team requires more information from the author tenet-performance Improve performance, flag performance regressions across core releases
Milestone

Comments

@shashidhar-ks
Copy link

.NET version

.NET 8 (8.0.8)

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

Private bytes of the .NET 8 Windows Form application keeps increasing, when we open and close a Form.

The steps to reproduce section has details on how to reproduce it faster in a simpler way.

I used memprofiler to confirm that there are no leaks in the source code I have used. Memprofiler mentioned that there are increase in the types of object as mentioned in the below image.

image

Note: We are calling GC.Collect() and GC.WaitForPendingFinalizer() at regular interval and still the private bytes of the application keeps increasing.

Steps to reproduce

WinFormsApp1.zip

  • Build the csproj in the above attachment.
  • Execute the output exe and click on the button.
  • Using Task Manager, monitor Private Bytes of the application every 3 mins for around 30 mins.
  • There will be a steady increase in the Private Bytes of the application

The application is doing the following:

  • We have Form2 that has checkbox, combobox and textbox controls (all from System.Windows.Forms namespace).
  • Form2 has hooked onto Load event in which it creates a Timer which is configured to call a function in one sec.
  • Function which Timer calls first stops the Time, Disposes it and closes the Form.
  • We have Form1 that has a button.
  • Clicking on the button does the following in an infinite loop
    • Creates instance of Form2, calls ShowDialog and disposes the instance when it is done.
    • Calls GC.Collect and GC.WaitForPendingFinalizer

So, clicking on the button will continuously creates and closes new Window Form.
By monitoring Private Bytes of the application, we can see that memory of the application keeps increasing.

@shashidhar-ks shashidhar-ks added the untriaged The team needs to look at this issue in the next triage label Sep 10, 2024
@JeremyKuhne
Copy link
Member

It looks like you have an accessibility tool running (as you're getting ControlAccessibleObjects). Trying this with both .NET 8 and 9 with and without Narrator running I didn't see anything particularly concerning.

.NET 9 RC1 will be out shortly and would be worth comparing. The accessibility interop code has been completely rewritten and may impact what you're observing.

@JeremyKuhne JeremyKuhne added 📭 waiting-author-feedback The team requires more information from the author and removed untriaged The team needs to look at this issue in the next triage labels Sep 10, 2024
@JeremyKuhne JeremyKuhne added this to the Future milestone Sep 10, 2024
@elachlan elachlan added the tenet-performance Improve performance, flag performance regressions across core releases label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📭 waiting-author-feedback The team requires more information from the author tenet-performance Improve performance, flag performance regressions across core releases
Projects
None yet
Development

No branches or pull requests

3 participants