Added disposal of the matrix

This commit is contained in:
RKrom 2014-06-09 19:47:15 +02:00
commit db7d38ef72

View file

@ -18,11 +18,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Greenshot.Configuration;
using Greenshot.Drawing;
using System; using System;
using System.Drawing; using System.Drawing;
using Greenshot.Drawing;
using Greenshot.Configuration;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
namespace Greenshot.Memento { namespace Greenshot.Memento {
@ -30,16 +30,16 @@ namespace Greenshot.Memento {
/// The SurfaceCropMemento makes it possible to undo-redo an surface crop /// The SurfaceCropMemento makes it possible to undo-redo an surface crop
/// </summary> /// </summary>
public class SurfaceBackgroundChangeMemento : IMemento { public class SurfaceBackgroundChangeMemento : IMemento {
private Image image; private Image _image;
private Surface surface; private Surface _surface;
private Matrix matrix; private Matrix _matrix;
public SurfaceBackgroundChangeMemento(Surface surface, Matrix matrix) { public SurfaceBackgroundChangeMemento(Surface surface, Matrix matrix) {
this.surface = surface; _surface = surface;
image = surface.Image; _image = surface.Image;
this.matrix = (Matrix)matrix.Clone(); _matrix = matrix.Clone();
// Make sure the reverse is applied // Make sure the reverse is applied
this.matrix.Invert(); _matrix.Invert();
} }
public void Dispose() { public void Dispose() {
@ -49,11 +49,15 @@ namespace Greenshot.Memento {
protected virtual void Dispose(bool disposing) { protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (image != null) { if (_matrix != null) {
image.Dispose(); _matrix.Dispose();
image = null; _matrix = null;
} }
surface = null; if (_image != null) {
_image.Dispose();
_image = null;
}
_surface = null;
} }
} }
@ -69,10 +73,9 @@ namespace Greenshot.Memento {
} }
public IMemento Restore() { public IMemento Restore() {
SurfaceBackgroundChangeMemento oldState = new SurfaceBackgroundChangeMemento(surface, matrix); SurfaceBackgroundChangeMemento oldState = new SurfaceBackgroundChangeMemento(_surface, _matrix);
_surface.UndoBackgroundChange(_image, _matrix);
surface.UndoBackgroundChange(image, matrix); _surface.Invalidate();
surface.Invalidate();
return oldState; return oldState;
} }
} }