Added IDisposable to ShapeManager and BaseShape

This commit is contained in:
Jaex 2016-08-19 13:22:12 +03:00
parent 72693d46d1
commit 2a115ed205
4 changed files with 32 additions and 6 deletions

View file

@ -800,6 +800,11 @@ protected override Image GetOutputImage()
protected override void Dispose(bool disposing)
{
if (ShapeManager != null)
{
ShapeManager.Dispose();
}
if (bmpBackgroundImage != null)
{
bmpBackgroundImage.Dispose();

View file

@ -24,13 +24,14 @@
#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()
{
}
}
}

View file

@ -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();
}
}
}
}

View file

@ -34,7 +34,7 @@
namespace ShareX.ScreenCaptureLib
{
internal class ShapeManager
internal class ShapeManager : IDisposable
{
public List<BaseShape> Shapes { get; private set; } = new List<BaseShape>();
@ -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();
}
}
}