fix: memory leak of some controls. (#1482)
This commit is contained in:
1 parent
a447ac3e75
commit
9092fe6ec7
4 files changed
+40
-3
No files matched your search
@@ -23,7 +23,7 @@ namespace HandyControl.Controls;
|
||||
[TemplatePart(Name = ElementBorderMove, Type = typeof(Border))]
|
||||
[TemplatePart(Name = ElementBorderBottom, Type = typeof(Border))]
|
||||
[TemplatePart(Name = ElementImageMain, Type = typeof(Image))]
|
||||
public class ImageViewer : Control
|
||||
public class ImageViewer : Control, IDisposable
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -167,6 +167,8 @@ public class ImageViewer : Control
|
||||
|
||||
private ImageBrowser _imageBrowser;
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
#endregion Data
|
||||
|
||||
#region ctor
|
||||
@@ -989,4 +991,25 @@ public class ImageViewer : Control
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ImageSource = null;
|
||||
_imageMain.Source = null;
|
||||
_imageMain.UpdateLayout();
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -110,6 +111,12 @@ public class ImageBrowser : Window
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
_imageViewer?.Dispose();
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private void ButtonClose_OnClick(object sender, RoutedEventArgs e) => Close();
|
||||
|
||||
private void PanelTopOnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
|
||||
Reference in new issue
Block a user