dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.1k stars 1.17k forks source link

Memory leaks on open window #9331

Open sandre58 opened 5 months ago

sandre58 commented 5 months ago

Description

WPF windows seem to cause memory leaks. Each time a window is opened, the RAM increases but does not decrease when the window is closed. If a window contains lots of controls, the memory can quickly increase to several GigaBytes. It seems that after closing the window, the application remembers Bindings and weakreferences to controls.

Reproduction Steps

Create an WPF application with a button which open a dialog (modal or not modal) window. This window contains 1000 textboxes (created dynamically in constructor). Open and close this windows several times.

Expected behavior

RAM decrease when we close window (same RAM before closing) Garbage collector is called when we close window.

Actual behavior

RAM increases every time I open the window and it hardly goes down when I close the window

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

h3xds1nz commented 5 months ago

Please provide a minimal repro project, it would ease up the troubleshooting.

lindexi commented 4 months ago

@sandre58 Sorry, I can not repro your issues. As @h3xds1nz says, could you provide more info?

sandre58 commented 4 months ago

Hello,

Thank you for your response.

Attached, a project to reproduce the problem. WpfApp1.zip

Simply open and close the window using the button. We see in the task manager that the memory increases each time and does not go down when we close the window. The windows are unfortunately not disposable.

lindexi commented 4 months ago

@sandre58 Sorry, I download and run your project. But I can not repro your issues. And I am afraid this is because you do not understand the memory related knowledge caused by misunderstanding

Please let me know if my steps are wrong.

harshit7962 commented 4 months ago

@sandre58 can you confirm if the steps followed above are correct and it is not dependent on specific application configurations.