From 2a115ed20580d94b0bcb2fd1b32d2d55b318df68 Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 19 Aug 2016 13:22:12 +0300 Subject: [PATCH] Added IDisposable to ShapeManager and BaseShape --- .../Forms/RectangleRegionForm.cs | 5 +++++ ShareX.ScreenCaptureLib/Shapes/BaseShape.cs | 7 ++++++- .../Shapes/Drawing/ImageDrawingShape.cs | 13 +++++++++---- ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs | 13 ++++++++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs index 16c0a42e7..c63b68a2f 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs @@ -800,6 +800,11 @@ protected override Image GetOutputImage() protected override void Dispose(bool disposing) { + if (ShapeManager != null) + { + ShapeManager.Dispose(); + } + if (bmpBackgroundImage != null) { bmpBackgroundImage.Dispose(); diff --git a/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs b/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs index 23c187d0d..54fd5d2e3 100644 --- a/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs @@ -24,13 +24,14 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) using ShareX.HelpersLib; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace ShareX.ScreenCaptureLib { - public abstract class BaseShape + public abstract class BaseShape : IDisposable { protected const int MinimumSize = 3; @@ -272,5 +273,9 @@ public virtual void OnNodePositionUpdate() Manager.ResizeNodes[(int)NodePosition.BottomLeft].Position = new Point(xStart, yEnd); Manager.ResizeNodes[(int)NodePosition.Left].Position = new Point(xStart, yMid); } + + public virtual void Dispose() + { + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs index 78f5cea1a..a1b0b6ada 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs @@ -35,10 +35,7 @@ public class ImageDrawingShape : BaseDrawingShape public void SetImage(Image img, Point pos) { - if (Image != null) - { - Image.Dispose(); - } + Dispose(); Image = img; @@ -52,5 +49,13 @@ public override void OnDraw(Graphics g) g.DrawImage(Image, Rectangle); } } + + public override void Dispose() + { + if (Image != null) + { + Image.Dispose(); + } + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 8d97dfa91..6c2abc3be 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License namespace ShareX.ScreenCaptureLib { - internal class ShapeManager + internal class ShapeManager : IDisposable { public List Shapes { get; private set; } = new List(); @@ -1544,6 +1544,7 @@ private void DeleteShape(BaseShape shape) { if (shape != null) { + shape.Dispose(); Shapes.Remove(shape); DeselectShape(shape); } @@ -1561,6 +1562,11 @@ private void DeleteIntersectShape() private void DeleteAllShapes() { + foreach (BaseShape shape in Shapes) + { + shape.Dispose(); + } + Shapes.Clear(); DeselectCurrentShape(); } @@ -1730,5 +1736,10 @@ private void OnCurrentShapeTypeChanged(ShapeType shapeType) CurrentShapeTypeChanged(shapeType); } } + + public void Dispose() + { + DeleteAllShapes(); + } } } \ No newline at end of file