以下代码中出现内存泄漏问题。 真实代码的摘录。
在CountChanged
绑定中,我看到了内存泄漏,但是对于ItemChanged
,没有这样的泄漏。我该怎么做才能解决此问题?
private IDisposable _whenActivated;
public MyWindowController(MyViewModel viewModel) : base("MyWindow")
{
ViewModel = viewModel;
_whenActivated = this.WhenActivated(disposables =>
{
var mainThread = RxApp.MainThreadScheduler;
//release issue starts
this.WhenAnyObservable(
x => x.ViewModel.MyArray.CountChanged)
.SubscribeOn(mainThread)
.Subscribe(x => _myListView.ReloadData())
.DisposeWith(disposables);
//release issue ends
// Below is very similar to above, but no leak
this.WhenAnyObservable(
x => x.ViewModel.MyArray.ItemChanged)
.SubscribeOn(mainThread)
.Subscribe(x => _myListView.ReloadData())
.DisposeWith(disposables);
});
}