内存泄漏Xamarin React绑定

时间:2018-10-31 13:17:17

标签: macos xamarin mvvm mvvmcross model-binding

以下代码中出现内存泄漏问题。 真实代码的摘录。

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);
    });
}

0 个答案:

没有答案