代码之家  ›  专栏  ›  技术社区  ›  Anoop Vaidya

内存泄漏Xamarin React Binding

  •  0
  • Anoop Vaidya  · 技术社区  · 8 年前

    从真实代码中提取。

    在 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 回复  |  直到 8 年前
    推荐文章