直截了当的位图内存泄漏

时间:2015-11-20 16:30:58

标签: c# memory-leaks bitmap

我正在编写一个例程,将各种类型的图像转换为PNG格式。以后不用保存,只需读入,写出来。据我所知,我正在处理我能做的一切。以下是相关代码:

public class FilterController : ApiController
{
    [HttpGet]
    [Route("orders")]
    public IHttpActionResult GetOrders()
    { }


    [HttpGet]
    [Route("customers")]
    public IHttpActionResult GetCustomers()
    { }


    [HttpPut]
    [Route("customers")]
    public IHttpActionResult UpdateOrders()
    { }
}

MemoryLog()中的关键行是:

            lock (mLocker)
            {
                startAvail = MemoryLog(LogLevel.Info, "ExtractI", "aOrig='" + aOrigImageName + "' got the lock");

                System.Drawing.Bitmap b;
                b = new System.Drawing.Bitmap(aFileName);
                string outfile = Path.Combine(mDocumentImageDir, aModImageName);
                b.Save(outfile, System.Drawing.Imaging.ImageFormat.Png);
                b.Dispose();

                MemoryLog(LogLevel.Info, "ExtractI", "aOrig='" + aOrigImageName + "' calling collect");
                GC.Collect();
                GC.WaitForPendingFinalizers();

                endAvail = MemoryLog(LogLevel.Info, "ExtractI", "aOrig='" + aOrigImageName + "' releasing lock");
                logger.Info("Diff: "+ (endAvail - startAvail)+"\r\n");
            }

我将此例程称为一系列图像,这是输出:

2015-11-20 11:22:00.793 |信息| ExtractI(image1):avail = 10971725824,priv = 0,aOrig =' image1.emf'得到了锁

2015-11-20 11:22:00.913 |信息| ExtractI(image1):avail = 10970079232,priv = 0,aOrig =' image1.emf'呼叫收集

2015-11-20 11:22:00.913 |信息| ExtractI(image1):avail = 10970034176,priv = 0,aOrig =' image1.emf'解锁

2015-11-20 11:22:00.913 | Info | Diff:-1691648

2015-11-20 11:22:00.943 |信息| ExtractI(image10):avail = 10970124288,priv = 0,aOrig =' image10.emf'得到了锁

2015-11-20 11:22:00.973 |信息| ExtractI(image10):avail = 10969792512,priv = 0,aOrig =' image10.emf'呼叫收集

2015-11-20 11:22:00.973 |信息| ExtractI(image10):avail = 10966958080,priv = 0,aOrig =' image10.emf'解锁

2015-11-20 11:22:00.973 | Info | Diff:-3166208

2015-11-20 11:22:00.993 |信息| ExtractI(image11):avail = 10966966272,priv = 0,aOrig =' image11.emf'得到了锁

2015-11-20 11:22:01.083 | Info | ExtractI(image11):avail = 10965856256,priv = 0,aOrig =' image11.emf'呼叫收集

2015-11-20 11:22:01.083 | Info | ExtractI(image11):avail = 10966171648,priv = 0,aOrig =' image11.emf'解锁

2015-11-20 11:22:01.083 | Info | Diff:-794624

内存仍在下降,而新的Bitmap()"如果大图像接近结束而不是接近开头,则挂起。我感谢任何给予的帮助,这似乎不是通常的"你需要调用dispose"问题

0 个答案:

没有答案