From 8fc25e312d697c61da7bc823e6fa68d53a018d87 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 20 Mar 2024 19:49:01 +0800 Subject: [PATCH] optimize: collect garbage after SetGrammar to avoid memory leak --- src/SourceGit/Models/TextMateHelper.cs | 4 +++- src/SourceGit/Views/RevisionFiles.axaml.cs | 2 +- src/SourceGit/Views/TextDiffView.axaml.cs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SourceGit/Models/TextMateHelper.cs b/src/SourceGit/Models/TextMateHelper.cs index d4f2c7aa..270cb507 100644 --- a/src/SourceGit/Models/TextMateHelper.cs +++ b/src/SourceGit/Models/TextMateHelper.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Avalonia.Styling; @@ -54,6 +55,7 @@ namespace SourceGit.Models var reg = installation.RegistryOptions as RegistryOptions; installation.SetGrammar(reg.GetScopeByExtension(ext)); + GC.Collect(); } } } diff --git a/src/SourceGit/Views/RevisionFiles.axaml.cs b/src/SourceGit/Views/RevisionFiles.axaml.cs index 82748c5f..80fcbc84 100644 --- a/src/SourceGit/Views/RevisionFiles.axaml.cs +++ b/src/SourceGit/Views/RevisionFiles.axaml.cs @@ -64,8 +64,8 @@ namespace SourceGit.Views var source = DataContext as Models.RevisionTextFile; if (source != null) { - Models.TextMateHelper.SetGrammarByFileName(_textMate, source.FileName); Text = source.Content; + Models.TextMateHelper.SetGrammarByFileName(_textMate, source.FileName); } } diff --git a/src/SourceGit/Views/TextDiffView.axaml.cs b/src/SourceGit/Views/TextDiffView.axaml.cs index 420f6a59..7e5e804a 100644 --- a/src/SourceGit/Views/TextDiffView.axaml.cs +++ b/src/SourceGit/Views/TextDiffView.axaml.cs @@ -317,8 +317,8 @@ namespace SourceGit.Views builder.AppendLine(line.Content); } - Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File); Text = builder.ToString(); + Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File); } else { @@ -675,8 +675,8 @@ namespace SourceGit.Views } } - Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File); Text = builder.ToString(); + Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File); } else {