Учитывая код, где resizedImage
имеет тип System.Drawing.Image
:
using (var resizedImage = Resizer.ResizeImage(bytes, requestedWidth))
{
return PNGCompressor.LosslesslyCompressPNG(resizedImage);
}
И метод определяется как:
public static byte[] LosslesslyCompressPNG(Image image)
{
var fileName = Guid.NewGuid();
var inputFilePath = TempCompressionFolder + fileName + ".png";
image.Save(inputFilePath, ImageFormat.Png);
var outputFilePath = TempCompressionFolder + fileName + "_comp.png";
var startInfo = new ProcessStartInfo
{
FileName = PathToOptiPNGExe,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
Arguments = "\"" + inputFilePath + "\" -out \"" + outputFilePath + "\" -o2 -strip all"
};
using (var process = Process.Start(startInfo))
{
if (process == null)
{
throw new Exception("Could not start " + PathToOptiPNGExe);
}
process.WaitForExit(Settings.Executables.WaitForExitMS);
if (!process.HasExited)
{
process.Kill();
}
}
var bytes = File.ReadAllBytes(outputFilePath);
File.Delete(outputFilePath);
File.Delete(inputFilePath);
return bytes;
}
Будет ли resizedImage
всегда утилизироваться ? Мне интересно, является ли это причиной утечки памяти или нет из-за запуска нового процесса.