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 having a Popup with an ItemsControl that uses a UserControl as DataTemplate, reopening the popup creates new instances of the UserControl and keeps the past ones on memory, never disposing of them. Removing the DataContext="{Binding}" from the xaml solves the leak.
The output console also prints [Binding]Error in binding to 'AvaloniaMemLeak.Controls.DropdownPackageControl'.'DataContext': 'Null value in expression '{empty}' at ''.'(DropdownPackageControl #...) every time for each new UserControl instance, I'm not sure why.
and bind the button's Click to the popup's Open on the code-behind. Open and close the popup many times and then take a snapshot of the heap using Visual Studio and search for "DropdownPackageControl". There will be many more instances than the 5 ones expected:
If you remove the DataContext="{Binding}" piece from the DataTemplate, the object count does not increase. Not sure if it replaces the old instances or caches them.
Expected behavior
Using DataContext={Binding} on a ItemsControl expected to not keep past UserControl instances on memory and thus cause no memory leak.
Periodic GC.Collect() calls have no effect.
Using .NET 8.0.
Same behavior with Avalonia 11.1.0-beta2.
Same behavior with ReactiveUserControl instead of UserControl.
Haven't tested default Avalonia controls with {Binding}.
Tested with and without x:CompileBindings.
Have confirmed that every Control under the Popup's logical tree is the same instance, except the UserControl (maybe also the ContentPresenter?). I might be mistaken though.
The text was updated successfully, but these errors were encountered:
Describe the bug
When having a Popup with an ItemsControl that uses a UserControl as DataTemplate, reopening the popup creates new instances of the UserControl and keeps the past ones on memory, never disposing of them. Removing the
DataContext="{Binding}"
from the xaml solves the leak.The output console also prints
[Binding]Error in binding to 'AvaloniaMemLeak.Controls.DropdownPackageControl'.'DataContext': 'Null value in expression '{empty}' at ''.'(DropdownPackageControl #...)
every time for each new UserControl instance, I'm not sure why.To Reproduce
Create a Window with a Xaml like so
and bind the button's
Click
to the popup'sOpen
on the code-behind. Open and close the popup many times and then take a snapshot of the heap using Visual Studio and search for "DropdownPackageControl". There will be many more instances than the 5 ones expected:If you remove the
DataContext="{Binding}"
piece from the DataTemplate, the object count does not increase. Not sure if it replaces the old instances or caches them.Expected behavior
Using
DataContext={Binding}
on a ItemsControl expected to not keep pastUserControl
instances on memory and thus cause no memory leak.Avalonia version
11.0.10
OS
Windows
Additional context
Repro repo: https://github.com/Arthur-Camatti/AvalPopupMemLeak.
Periodic
GC.Collect()
calls have no effect.Using .NET 8.0.
Same behavior with Avalonia
11.1.0-beta2
.Same behavior with
ReactiveUserControl
instead ofUserControl
.Haven't tested default Avalonia controls with
{Binding}
.Tested with and without
x:CompileBindings
.Have confirmed that every Control under the Popup's logical tree is the same instance, except the UserControl (maybe also the ContentPresenter?). I might be mistaken though.
The text was updated successfully, but these errors were encountered: