Open balthild opened 4 years ago
I've also run into this problem.
Could it be that NeverEndingSynchronousCompletionAsyncResultObservable.Subscribe
doesn't set _asyncResult
to null on the async path through the code?
public IDisposable Subscribe(IObserver<T> observer)
{
if (_asyncResult?.IsCompleted == true)
{
_value = _asyncResult.Value.GetResult();
_asyncResult = null;
}
if (_asyncResult != null)
_asyncResult.Value.OnCompleted(() =>
{
observer.OnNext(_asyncResult.Value.GetResult());
// _asyncResult = null; // would adding this fix the memory leak?
});
else
observer.OnNext(_value);
// _value= null; // would adding this fix the memory leak?
return Disposable.Empty;
}
@aguahombre I think that code is only referencing the Window from the ListBox item, not the other way around, so it's probably not related to the issue
Demo: https://github.com/balthild/avalonia-memory-leak-example
Binding to parent control in DataTemplate of ListBox creates objects that cannot be GC'ed. It seems that if a lot of items are shown in a ListBox and then removed, the items are not recycled.
If I change the binding
{Binding #MainWindow.Title}
to{Binding $parent[Window].Title}
, the memory leak will disappear.MainWindow.xaml
MainWindowViewModel.cs