mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07: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="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void OnAppDeactivated(object sender, EventArgs e) {
|
private void OnAppDeactivated(object sender, EventArgs e) {
|
||||||
|
GC.Collect();
|
||||||
if (!restart) Models.Preference.Save();
|
if (!restart) Models.Preference.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,21 @@ namespace SourceGit.Views.Controls {
|
||||||
|
|
||||||
public Avatar() {
|
public Avatar() {
|
||||||
SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
|
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>
|
/// <summary>
|
||||||
|
@ -139,15 +154,7 @@ namespace SourceGit.Views.Controls {
|
||||||
Avatar a = d as Avatar;
|
Avatar a = d as Avatar;
|
||||||
if (a == null) return;
|
if (a == null) return;
|
||||||
|
|
||||||
var oldEmail = e.OldValue as string;
|
a.Cancel(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.Source = null;
|
a.Source = null;
|
||||||
a.InvalidateVisual();
|
a.InvalidateVisual();
|
||||||
|
|
||||||
|
@ -181,6 +188,8 @@ namespace SourceGit.Views.Controls {
|
||||||
requesting[email].Add(a);
|
requesting[email].Add(a);
|
||||||
|
|
||||||
Action job = () => {
|
Action job = () => {
|
||||||
|
if (!requesting.ContainsKey(email)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
|
HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
|
||||||
req.Timeout = 2000;
|
req.Timeout = 2000;
|
||||||
|
|
|
@ -87,10 +87,11 @@ namespace SourceGit.Views {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTabClosed(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
private void OnTabClosed(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
||||||
|
Controls.PopupWidget.UnregisterContainer(e.TabId);
|
||||||
Models.Watcher.Close(e.TabId);
|
Models.Watcher.Close(e.TabId);
|
||||||
Commands.AutoFetch.Stop(e.TabId);
|
Commands.AutoFetch.Stop(e.TabId);
|
||||||
container.Remove(e.TabId);
|
container.Remove(e.TabId);
|
||||||
Controls.PopupWidget.UnregisterContainer(e.TabId);
|
GC.Collect();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,15 @@ namespace SourceGit.Views.Widgets {
|
||||||
watcher.StashChanged += UpdateStashes;
|
watcher.StashChanged += UpdateStashes;
|
||||||
watcher.TagChanged += UpdateTags;
|
watcher.TagChanged += UpdateTags;
|
||||||
watcher.SubmoduleChanged += UpdateSubmodules;
|
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
|
#region POPUP
|
||||||
|
|
|
@ -27,6 +27,12 @@ namespace SourceGit.Views.Widgets {
|
||||||
var watcher = Models.Watcher.Get(repo.Path);
|
var watcher = Models.Watcher.Get(repo.Path);
|
||||||
watcher.BranchChanged += UpdateCommits;
|
watcher.BranchChanged += UpdateCommits;
|
||||||
watcher.TagChanged += UpdateCommits;
|
watcher.TagChanged += UpdateCommits;
|
||||||
|
|
||||||
|
Unloaded += (o, e) => {
|
||||||
|
cachedCommits.Clear();
|
||||||
|
commitList.ItemsSource = cachedCommits;
|
||||||
|
graph.SetData(cachedCommits, false);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#region DATA
|
#region DATA
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
public RevisionFiles() {
|
public RevisionFiles() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Unloaded += (o, e) => treeFiles.ItemsSource = new List<FileNode>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetData(string repo, string sha, Commands.Context cancelToken) {
|
public void SetData(string repo, string sha, Commands.Context cancelToken) {
|
||||||
|
|
Loading…
Reference in a new issue