mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
fix<*>: add cleanups to fix memory leak
This commit is contained in:
parent
13ab3d1eae
commit
c3b1b6d502
6 changed files with 37 additions and 10 deletions
|
@ -120,6 +120,7 @@ namespace SourceGit {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnAppDeactivated(object sender, EventArgs e) {
|
||||
GC.Collect();
|
||||
if (!restart) Models.Preference.Save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,21 @@ namespace SourceGit.Views.Controls {
|
|||
|
||||
public Avatar() {
|
||||
SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
|
||||
Unloaded += (o, e) => Cancel(Email);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消一个下载任务
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<Models.Tag>();
|
||||
submoduleList.ItemsSource = new List<string>();
|
||||
};
|
||||
}
|
||||
|
||||
#region POPUP
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
public RevisionFiles() {
|
||||
InitializeComponent();
|
||||
Unloaded += (o, e) => treeFiles.ItemsSource = new List<FileNode>();
|
||||
}
|
||||
|
||||
public void SetData(string repo, string sha, Commands.Context cancelToken) {
|
||||
|
|
Loading…
Reference in a new issue