diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2015-05-23 10:19:01 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2015-05-23 10:19:01 +0300 |
commit | 1800f8358a79ecea75b16f5a0a9c6f1f3fbd94d8 (patch) | |
tree | 6295c01a408b4d1a8f9df4d253394f764ccff74f /main/src/addins/MonoDevelop.HexEditor | |
parent | 5fcf2ce132fa20c7a314c302f43e96f0ac7e6e69 (diff) |
[HexEditor] Fixed memory leaks.
Diffstat (limited to 'main/src/addins/MonoDevelop.HexEditor')
3 files changed, 42 insertions, 11 deletions
diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs index 95c2463dc5..af3ba7c679 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs @@ -160,6 +160,19 @@ namespace Mono.MHex Options = HexEditorOptions.DefaultOptions; Options.Changed += OptionsChanged; } + + protected override void Dispose (bool disposing) + { + if (disposing) { + Options.Changed -= OptionsChanged; + if (caretTimer != null) { + caretTimer.Elapsed -= UpdateCaret; + caretTimer.Dispose (); + caretTimer = null; + } + } + base.Dispose (disposing); + } public void PurgeLayoutCaches () { diff --git a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorView.cs b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorView.cs index 44fc7fac18..e01cddac17 100644 --- a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorView.cs +++ b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorView.cs @@ -51,15 +51,25 @@ namespace MonoDevelop.HexEditor { hexEditor.HexEditorStyle = new MonoDevelopHexEditorStyle (hexEditor); SetOptions (); - DefaultSourceEditorOptions.Instance.Changed += delegate { - SetOptions (); - }; + DefaultSourceEditorOptions.Instance.Changed += Instance_Changed; hexEditor.HexEditorData.Replaced += delegate { this.IsDirty = true; }; window = new ScrollView (hexEditor); } - + + public override void Dispose () + { + ((MonoDevelopHexEditorStyle)hexEditor.HexEditorStyle).Dispose (); + DefaultSourceEditorOptions.Instance.Changed -= Instance_Changed; + base.Dispose (); + } + + void Instance_Changed (object sender, EventArgs e) + { + SetOptions (); + } + void SetOptions () { var name = FontService.FilterFontName (FontService.GetUnderlyingFontName ("Editor")); diff --git a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/MonoDevelopHexEditorStyle.cs b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/MonoDevelopHexEditorStyle.cs index 6e68a8807c..c77914e172 100644 --- a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/MonoDevelopHexEditorStyle.cs +++ b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/MonoDevelopHexEditorStyle.cs @@ -35,7 +35,7 @@ using MonoDevelop.Ide.Editor.Highlighting; namespace MonoDevelop.HexEditor { - class MonoDevelopHexEditorStyle : HexEditorStyle + class MonoDevelopHexEditorStyle : HexEditorStyle, IDisposable { ColorScheme colorStyle; Mono.MHex.HexEditor hexEditor; @@ -44,12 +44,15 @@ namespace MonoDevelop.HexEditor { this.hexEditor = hexEditor; SetStyle (); - IdeApp.Preferences.ColorScheme.Changed += delegate { - SetStyle (); - this.hexEditor.Options.RaiseChanged (); - this.hexEditor.PurgeLayoutCaches (); - this.hexEditor.Repaint (); - }; + IdeApp.Preferences.ColorScheme.Changed += ColorSchemeChanged; + } + + void ColorSchemeChanged (object sender, EventArgs e) + { + SetStyle (); + this.hexEditor.Options.RaiseChanged (); + this.hexEditor.PurgeLayoutCaches (); + this.hexEditor.Repaint (); } void SetStyle () @@ -62,6 +65,11 @@ namespace MonoDevelop.HexEditor return new Color (foreground.R, foreground.G, foreground.B, foreground.A); } + public void Dispose () + { + IdeApp.Preferences.ColorScheme.Changed -= ColorSchemeChanged; + } + public override Color HexOffset { get { return ConvertColor (colorStyle.LineNumbers.Foreground); |