From ac43abbed2bee4c13f1a3b7b9ea63aaab991c2a1 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Sun, 6 Oct 2024 12:04:41 +0200 Subject: [PATCH 1/2] Fix potential memory leak: Dispose is never called! --- ILSpy/TextView/DecompilerTextView.cs | 34 ++++++++++++++------------ ILSpy/TextView/DecompilerTextView.xaml | 1 - 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index bbcc3674fc..77a2ee89ad 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -72,7 +72,7 @@ namespace ICSharpCode.ILSpy.TextView /// Manages the TextEditor showing the decompiled code. /// Contains all the threading logic that makes the decompiler work in the background. /// - public sealed partial class DecompilerTextView : UserControl, IDisposable, IHaveState, IProgress + public sealed partial class DecompilerTextView : UserControl, IHaveState, IProgress { readonly ReferenceElementGenerator referenceElementGenerator; readonly UIElementGenerator uiElementGenerator; @@ -125,7 +125,8 @@ public DecompilerTextView() textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.ShowLineNumbers = true; - SettingsService.Instance.DisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged; + + MessageBus.Subscribers += Settings_Changed; // SearchPanel SearchPanel searchPanel = SearchPanel.Install(textEditor.TextArea); @@ -179,15 +180,24 @@ void RemoveEditCommand(RoutedUICommand command) #region Line margin - void CurrentDisplaySettings_PropertyChanged(object? sender, PropertyChangedEventArgs e) + private void Settings_Changed(object? sender, SettingsChangedEventArgs e) { - if (e.PropertyName == nameof(DisplaySettings.ShowLineNumbers)) - { - ShowLineMargin(); - } - else if (e.PropertyName == nameof(DisplaySettings.HighlightCurrentLine)) + Settings_PropertyChanged(sender, e); + } + + private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (sender is not DisplaySettings) + return; + + switch (e.PropertyName) { - SetHighlightCurrentLine(); + case nameof(DisplaySettings.ShowLineNumbers): + ShowLineMargin(); + break; + case nameof(DisplaySettings.HighlightCurrentLine): + SetHighlightCurrentLine(); + break; } } @@ -1286,12 +1296,6 @@ public static void RegisterHighlighting() HighlightingManager.Instance.RegisterHighlighting("xml", new[] { ".xml", ".baml" }, "XML-Mode"); } - - public void Dispose() - { - SettingsService.Instance.DisplaySettings.PropertyChanged -= CurrentDisplaySettings_PropertyChanged; - } - #region Unfold public void UnfoldAndScroll(int lineNumber) { diff --git a/ILSpy/TextView/DecompilerTextView.xaml b/ILSpy/TextView/DecompilerTextView.xaml index 0b9f701e59..5a61fc0fa4 100644 --- a/ILSpy/TextView/DecompilerTextView.xaml +++ b/ILSpy/TextView/DecompilerTextView.xaml @@ -7,7 +7,6 @@ xmlns:editing="clr-namespace:ICSharpCode.AvalonEdit.Editing;assembly=ICSharpCode.AvalonEdit" xmlns:folding="clr-namespace:ICSharpCode.AvalonEdit.Folding;assembly=ICSharpCode.AvalonEdit" xmlns:styles="urn:TomsToolbox.Wpf.Styles" - xmlns:toms="urn:TomsToolbox" xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes"> From 91dbea2b2bf1e27007977b906fc41fa1ea4e47f2 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Sun, 6 Oct 2024 12:06:53 +0200 Subject: [PATCH 2/2] Fix #3293: Right panel shows old info in case all is deleted in the left-hand tree => start decompile with no content to finally show an empty panel. --- ILSpy/AssemblyTree/AssemblyTreeModel.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index 63ce158f6f..322930a6c7 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -716,7 +716,12 @@ private void LoadAssemblies(IEnumerable fileNames, List? private void TreeView_SelectionChanged() { - if (SelectedItems.Length > 0) + if (SelectedItems.Length <= 0) + { + // To cancel any pending decompilation requests and show an empty tab + DecompileSelectedNodes(); + } + else { var activeTabPage = DockWorkspace.Instance.ActiveTabPage;