【发布时间】:2020-01-17 16:29:20
【问题描述】:
鉴于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 会一直被处理掉吗?我想知道这是否是由于新进程正在启动而导致内存泄漏的原因。
【问题讨论】:
标签: c# asp.net memory-leaks idisposable