From ba342dfd9f8285fe4300443aafbce123aa21687a Mon Sep 17 00:00:00 2001 From: Pavle Arezina <arezinp@mcmaster.ca> Date: Mon, 28 Nov 2016 11:13:09 -0500 Subject: [PATCH] Resolved issue of Opening non Gifs, Model is now also disposable for memory leak resolving --- src/Gifitti/Gifitti/Models/GifModel.cs | 10 ++++++---- .../Gifitti/View_Models/MainForm.Designer.cs | 13 +++++++------ src/Gifitti/Gifitti/View_Models/MainForm.cs | 3 +++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs index e55a173..f1cefd2 100644 --- a/src/Gifitti/Gifitti/Models/GifModel.cs +++ b/src/Gifitti/Gifitti/Models/GifModel.cs @@ -14,7 +14,7 @@ namespace Gifitti.Models /// <summary> /// Software model of a GIF, Encapsulated with bassic opperations on GIF images. /// </summary> - public class GifModel + public class GifModel : IDisposable { public Image gifImage { get; set; } public Image originalGif { get; private set; } @@ -35,9 +35,6 @@ namespace Gifitti.Models public GifModel(String path) { Console.WriteLine(Path.GetExtension(path)); - - if (!Path.GetExtension(path).ToLower().Equals(".gif")) - throw new FileLoadException("Invalid Extension Specified"); //Save the original Gif originalGif = Image.FromFile(path); this.gifImage = originalGif.Clone() as Image; @@ -202,5 +199,10 @@ namespace Gifitti.Models { frames[index] = frame; } + + public void Dispose() + { + this.frames = null; + } } } diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs b/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs index 4101995..25f44d7 100644 --- a/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs +++ b/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs @@ -67,7 +67,7 @@ namespace Gifitti.View_Models // gifView // this.gifView.Location = new System.Drawing.Point(9, 10); - this.gifView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.gifView.Margin = new System.Windows.Forms.Padding(2); this.gifView.Name = "gifView"; this.gifView.Size = new System.Drawing.Size(456, 382); this.gifView.TabIndex = 2; @@ -152,7 +152,7 @@ namespace Gifitti.View_Models this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.textBox1.Enabled = false; this.textBox1.Location = new System.Drawing.Point(214, 448); - this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox1.Margin = new System.Windows.Forms.Padding(2); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(23, 20); this.textBox1.TabIndex = 3; @@ -163,7 +163,7 @@ namespace Gifitti.View_Models this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.textBox2.Enabled = false; this.textBox2.Location = new System.Drawing.Point(240, 448); - this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox2.Margin = new System.Windows.Forms.Padding(2); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(23, 20); this.textBox2.TabIndex = 4; @@ -174,7 +174,7 @@ namespace Gifitti.View_Models this.button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.button3.Enabled = false; this.button3.Location = new System.Drawing.Point(266, 445); - this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button3.Margin = new System.Windows.Forms.Padding(2); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(50, 24); this.button3.TabIndex = 5; @@ -224,7 +224,7 @@ namespace Gifitti.View_Models // this.trackBar1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.trackBar1.Location = new System.Drawing.Point(328, 448); - this.trackBar1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.trackBar1.Margin = new System.Windows.Forms.Padding(2); this.trackBar1.Name = "trackBar1"; this.trackBar1.Size = new System.Drawing.Size(137, 45); this.trackBar1.TabIndex = 9; @@ -271,7 +271,8 @@ namespace Gifitti.View_Models this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.gifView); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); + this.MaximizeBox = false; this.Menu = this.mainMenu1; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.cs b/src/Gifitti/Gifitti/View_Models/MainForm.cs index 7ade011..ef71c02 100644 --- a/src/Gifitti/Gifitti/View_Models/MainForm.cs +++ b/src/Gifitti/Gifitti/View_Models/MainForm.cs @@ -258,6 +258,9 @@ namespace Gifitti.View_Models { try { + if (!Path.GetExtension(file).ToLower().Equals(".gif")) + throw new FileLoadException("Invalid Extension Specified"); + gm?.Dispose(); gm = new GifModel(file); gm.ReverseAtEnd = false; Image loadedGif = gm.gifImage; -- GitLab