diff --git a/src/App.xaml.cs b/src/App.xaml.cs index dadd88be..f4b5e643 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -120,6 +120,7 @@ namespace SourceGit { /// /// private void OnAppDeactivated(object sender, EventArgs e) { + GC.Collect(); if (!restart) Models.Preference.Save(); } } diff --git a/src/Views/Controls/Avatar.cs b/src/Views/Controls/Avatar.cs index eebd2264..5dfe9eb7 100644 --- a/src/Views/Controls/Avatar.cs +++ b/src/Views/Controls/Avatar.cs @@ -80,6 +80,21 @@ namespace SourceGit.Views.Controls { public Avatar() { SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); + Unloaded += (o, e) => Cancel(Email); + } + + /// + /// 取消一个下载任务 + /// + /// + private void Cancel(string email) { + if (!string.IsNullOrEmpty(email) && requesting.ContainsKey(email)) { + if (requesting[email].Count <= 1) { + requesting.Remove(email); + } else { + requesting[email].Remove(this); + } + } } /// @@ -139,15 +154,7 @@ namespace SourceGit.Views.Controls { Avatar a = d as Avatar; if (a == null) return; - var oldEmail = e.OldValue as string; - if (!string.IsNullOrEmpty(oldEmail) && requesting.ContainsKey(oldEmail)) { - if (requesting[oldEmail].Count <= 1) { - requesting.Remove(oldEmail); - } else { - requesting[oldEmail].Remove(a); - } - } - + a.Cancel(e.OldValue as string); a.Source = null; a.InvalidateVisual(); @@ -181,6 +188,8 @@ namespace SourceGit.Views.Controls { requesting[email].Add(a); Action job = () => { + if (!requesting.ContainsKey(email)) return; + try { HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404"); req.Timeout = 2000; diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index d5ca5344..2f2d3964 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -87,10 +87,11 @@ namespace SourceGit.Views { } private void OnTabClosed(object sender, Widgets.PageTabBar.TabEventArgs e) { + Controls.PopupWidget.UnregisterContainer(e.TabId); Models.Watcher.Close(e.TabId); Commands.AutoFetch.Stop(e.TabId); container.Remove(e.TabId); - Controls.PopupWidget.UnregisterContainer(e.TabId); + GC.Collect(); } #endregion } diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index bae2ecee..0ed1c376 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -68,6 +68,15 @@ namespace SourceGit.Views.Widgets { watcher.StashChanged += UpdateStashes; watcher.TagChanged += UpdateTags; watcher.SubmoduleChanged += UpdateSubmodules; + + Unloaded += (o, e) => { + localBranches.Clear(); + remoteBranches.Clear(); + localBranchTree.ItemsSource = localBranches; + remoteBranchTree.ItemsSource = remoteBranches; + tagList.ItemsSource = new List(); + submoduleList.ItemsSource = new List(); + }; } #region POPUP diff --git a/src/Views/Widgets/Histories.xaml.cs b/src/Views/Widgets/Histories.xaml.cs index 73f6a126..be900ac1 100644 --- a/src/Views/Widgets/Histories.xaml.cs +++ b/src/Views/Widgets/Histories.xaml.cs @@ -27,6 +27,12 @@ namespace SourceGit.Views.Widgets { var watcher = Models.Watcher.Get(repo.Path); watcher.BranchChanged += UpdateCommits; watcher.TagChanged += UpdateCommits; + + Unloaded += (o, e) => { + cachedCommits.Clear(); + commitList.ItemsSource = cachedCommits; + graph.SetData(cachedCommits, false); + }; } #region DATA diff --git a/src/Views/Widgets/RevisionFiles.xaml.cs b/src/Views/Widgets/RevisionFiles.xaml.cs index 4e6fcb55..904ac54b 100644 --- a/src/Views/Widgets/RevisionFiles.xaml.cs +++ b/src/Views/Widgets/RevisionFiles.xaml.cs @@ -31,6 +31,7 @@ namespace SourceGit.Views.Widgets { public RevisionFiles() { InitializeComponent(); + Unloaded += (o, e) => treeFiles.ItemsSource = new List(); } public void SetData(string repo, string sha, Commands.Context cancelToken) {