Bitmap.Save, Huge Memory Leak

前端 未结 5 1074
情歌与酒
情歌与酒 2021-01-16 05:02

I have an application where I am taking a bitmap and compressing it using a GZipStream and sending it over a socket, all in memory. I have tracked down the dirty scumbag mem

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 05:43

    Okay, after trying everyones ideas and thoughts and numerous other methods. I finally tried the simple:

    using (frame) {
        frame.Save(outStream, jpegCodec, parameters);
    }
    

    And well, this worked and the memory leak is fixed.. I tried forcefully invoking the garbage collector, disposing the bitmap manually, using P/Invoke DeleteObject, nothing worked, but using a using statement did. So this makes me wonder what happens underthehood on a using statement that I'm missing out on....

提交回复
热议问题