fix memory leaks in history tab.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
+using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using WalletWasabi.Models;
@@ -17,20 +18,40 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private SortOrder _dateSortDirection;
private SortOrder _amountSortDirection;
private SortOrder _transactionSortDirection;
+ private CompositeDisposable _disposables;
public ReactiveCommand SortCommand { get; }
public HistoryTabViewModel(WalletViewModel walletViewModel)
: base("History", walletViewModel)
{
- throw new Exception("TODO");
+ Transactions = new ObservableCollection<TransactionViewModel>();
- // memory leak fixes.
+ RewriteTableAsync().GetAwaiter();
- Transactions = new ObservableCollection<TransactionViewModel>();
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- RewriteTableAsync();
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
+ this.WhenAnyValue(x => x.SelectedTransaction).Subscribe(transaction =>
+ {
+ if (Global.UiConfig.Autocopy is true)
+ {
+ transaction?.CopyToClipboard();
+ }
+ });
+
+ SortCommand = ReactiveCommand.Create(() => RefreshOrdering());
+
+ DateSortDirection = SortOrder.Decreasing;
+ }
+
+ public override void OnOpen()
+ {
+ base.OnOpen();
+
+ if (_disposables != null)
+ {
+ throw new Exception("Histroy Tab was opened before it was closed.");
+ }
+
+ _disposables = new CompositeDisposable();
var coinsChanged = Observable.FromEventPattern(Global.WalletService.Coins, nameof(Global.WalletService.Coins.CollectionChanged));
var newBlockProcessed = Observable.FromEventPattern(Global.WalletService, nameof(Global.WalletService.NewBlockProcessed));
@@ -41,24 +62,15 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
.Merge(coinSpent)
.Throttle(TimeSpan.FromSeconds(5))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(_ =>
- {
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- RewriteTableAsync();
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- });
-
- this.WhenAnyValue(x => x.SelectedTransaction).Subscribe(transaction =>
- {
- if (Global.UiConfig.Autocopy is true)
- {
- transaction?.CopyToClipboard();
+ .Subscribe(async _ => await RewriteTableAsync())
+ .DisposeWith(_disposables);
}
- });
- SortCommand = ReactiveCommand.Create(() => RefreshOrdering());
+ public override bool OnClose()
+ {
+ _disposables.Dispose();
- DateSortDirection = SortOrder.Decreasing;
+ return base.OnClose();
}
private async Task RewriteTableAsync()
@@ -281,12 +293,5 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
}
-
- public override bool OnClose()
- {
- return base.OnClose();
- }
-
-
}
}

fix memory leaks in history tab.