Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Drawing.Image.FromFile“;System.OutOfMemoryException:内存不足;_C#_.net_Out Of Memory_System.drawing - Fatal编程技术网

C# System.Drawing.Image.FromFile“;System.OutOfMemoryException:内存不足;

C# System.Drawing.Image.FromFile“;System.OutOfMemoryException:内存不足;,c#,.net,out-of-memory,system.drawing,C#,.net,Out Of Memory,System.drawing,我偶尔会犯这些错误,我不知道为什么。这段代码每天执行数千次,我每隔一段时间就会收到这些错误。其中一个图像为94.9KB,1024x1024图像。正在通过UNC路径从Azure文件存储磁盘读取映像 System.OutOfMemoryException: Out of memory. Generated: Sat, 23 Apr 2016 15:09:54 GMT System.OutOfMemoryException: Out of memory. at System.Drawing.

我偶尔会犯这些错误,我不知道为什么。这段代码每天执行数千次,我每隔一段时间就会收到这些错误。其中一个图像为94.9KB,1024x1024图像。正在通过
UNC
路径从
Azure文件存储
磁盘读取映像

System.OutOfMemoryException: Out of memory.

Generated: Sat, 23 Apr 2016 15:09:54 GMT

System.OutOfMemoryException: Out of memory.
   at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
   at System.Drawing.Image.FromFile(String filename)
   at Tournaments.ImageHandler.ProcessRequest(HttpContext context) in C:\Development\Exposure\Main\Websites\Tournaments\ImageHandler.ashx.cs:line 64
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
实际代码

 using (var image = Image.FromFile(path))
 {
 }

这似乎解决了我的问题,因为它没有以这种方式引用它

  using (var memoryStream = new MemoryStream(File.ReadAllBytes(path)))
            {
                using (var image = Image.FromStream(memoryStream))
                {

这似乎解决了我的问题,因为它没有以这种方式引用它

  using (var memoryStream = new MemoryStream(File.ReadAllBytes(path)))
            {
                using (var image = Image.FromStream(memoryStream))
                {

这表明某个地方有内存泄漏。我在上面发布了代码。.NET framework中的内存泄漏?内存泄漏可能发生在
Tournaments.ImageHandler.ProcessRequest
中,但是,这也可能是由于图像太大或标题数据不正确造成的。我在浏览器中打开了相同的URL,加载得很好。虽然这是一个很大的形象,但为什么会造成这种情况呢?这张图片并没有我上面贴的那么大。请注意,GDI+在识别OutOfMemoryException的原因方面非常糟糕。这可能是因为图像标题被刷新了,或者有许多不同的原因!查看问题的答案!这表明某个地方有内存泄漏。我在上面发布了代码。.NET framework中的内存泄漏?内存泄漏可能发生在
Tournaments.ImageHandler.ProcessRequest
中,但是,这也可能是由于图像太大或标题数据不正确造成的。我在浏览器中打开了相同的URL,加载得很好。虽然这是一个很大的形象,但为什么会造成这种情况呢?这张图片并没有我上面贴的那么大。请注意,GDI+在识别OutOfMemoryException的原因方面非常糟糕。这可能是因为图像标题被刷新了,或者有许多不同的原因!查看问题的答案!