You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a ListBox control with ListBoxItem in a WPF Navigation Window, opening and closing the window multiple times leads to memory leaks. The ListBox and its related objects are not released from memory, as confirmed using the .NET Memory Profiler.
Reproduction Steps
Create a WPF Navigation Window with a ListBox containing ListBoxItems.
Open the navigation window multiple times and close it.
Use a memory profiler to observe memory allocations.
Notice that ListBox, ListBoxItem, and other related objects like Event from ItemContainerGenerator and ItemCollection remain in memory.
When the Navigation Window is closed, the ListBox and its child elements should be released, and garbage collection should reclaim the memory.
Actual behavior
The ListBox, ListBoxItem, and related objects like Event from ItemContainerGenerator and ItemCollection remain in memory, causing an accumulation of memory usage over time, leading to a memory leak.
Regression?
Not sure if this issue was present in previous versions of WPF.
Known Workarounds
No response
Impact
The memory leak leads to increased memory usage in applications that frequently open and close Navigation Windows, eventually causing performance degradation.
Configuration
No response
Other information
Attached the reference image
The text was updated successfully, but these errors were encountered:
I'd say this just a misunderstanding on how Garbage collection works. I've tested your sample briefly.
Instead of pressing a button; go big, add a DispatcherTimer to open the window each 400 ms for example; add this to your Window1 so you can see it was actually fully loaded for the full graphical image.
privateasyncvoidWindow_Loaded(objectsender,RoutedEventArgse){awaitTask.Delay(200);// cause eager event exitthis.Close();}
And after you've opened and closed the window 10k times for example (up to you how long you want to wait), force the collection via snapshot, measure the objects and heap usage (or search for the mentioned ListBoxItem directly for example); you'll see you're back to the amount as when you've opened the window the first time.
Description
When using a ListBox control with ListBoxItem in a WPF Navigation Window, opening and closing the window multiple times leads to memory leaks. The ListBox and its related objects are not released from memory, as confirmed using the .NET Memory Profiler.
Reproduction Steps
Refer the attached sample to replicate the issue.
TextBoxExtSample.zip
Expected behavior
When the Navigation Window is closed, the ListBox and its child elements should be released, and garbage collection should reclaim the memory.
Actual behavior
The ListBox, ListBoxItem, and related objects like Event from ItemContainerGenerator and ItemCollection remain in memory, causing an accumulation of memory usage over time, leading to a memory leak.
Regression?
Not sure if this issue was present in previous versions of WPF.
Known Workarounds
No response
Impact
The memory leak leads to increased memory usage in applications that frequently open and close Navigation Windows, eventually causing performance degradation.
Configuration
No response
Other information
Attached the reference image
The text was updated successfully, but these errors were encountered: