From b313504553a2f650e1256b40110bb3f04f1adde2 Mon Sep 17 00:00:00 2001 From: James South Date: Thu, 14 Apr 2016 00:25:02 +1000 Subject: [PATCH] Fix memory leak in sampler tests Former-commit-id: 4b9ffafdd826522b192bfeb8411faefee7621a16 Former-commit-id: 560f124d694ee156b4a1e7e6a0c2d92ee87edc0e Former-commit-id: 672cf548c6014bfbd4ec4453d1b029e11091f533 --- .../Processors/Samplers/SamplerTests.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs index d80556721..e7d40a35b 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs @@ -61,6 +61,7 @@ Stopwatch watch = Stopwatch.StartNew(); Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); + using (FileStream output = File.OpenWrite($"TestOutput/Sample/{ Path.GetFileName(filename) }")) { processor.OnProgress += this.ProgressUpdate; @@ -69,6 +70,7 @@ processor.OnProgress -= this.ProgressUpdate; } + image.Dispose(); Trace.WriteLine($"{ name }: { watch.ElapsedMilliseconds}ms"); } } @@ -88,8 +90,9 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) { image.Resize(image.Width / 2, image.Height / 2, sampler, false, this.ProgressUpdate) @@ -116,8 +119,9 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) { image.Resize(image.Width / 3, 0, new TriangleResampler(), false, this.ProgressUpdate) @@ -144,8 +148,9 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) { image.Resize(0, image.Height / 3, new TriangleResampler(), false, this.ProgressUpdate) @@ -171,8 +176,9 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/RotateFlip/{filename}")) { image.RotateFlip(rotateType, flipType, this.ProgressUpdate) @@ -197,8 +203,10 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); + string filename = Path.GetFileName(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/Rotate/{filename}")) { image.Rotate(45, this.ProgressUpdate) @@ -223,8 +231,10 @@ using (FileStream stream = File.OpenRead(file)) { Stopwatch watch = Stopwatch.StartNew(); - Image image = new Image(stream); + string filename = Path.GetFileName(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/Skew/{filename}")) { image.Skew(45, 45, this.ProgressUpdate) @@ -248,8 +258,9 @@ { using (FileStream stream = File.OpenRead(file)) { - Image image = new Image(stream); string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCrop" + Path.GetExtension(file); + + using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite($"TestOutput/EntropyCrop/{filename}")) { image.EntropyCrop(.5f, this.ProgressUpdate).Save(output);