.Net and Bitmap not automatically disposed by GC when there is no memory left

后端 未结 3 826
野性不改
野性不改 2020-11-27 08:16

I\'m wondering how does the allocation and disposal of memory allocated for bitmaps work in .NET.

When I do a lot of bitmap creations in loops in a function and call

3条回答
  •  北海茫月
    2020-11-27 08:58

    The .NET Bitmap class "encapsulates a GDI+ bitmap", that means you should call Dispose on a Bitmap when you are finished with it,

    "Always call Dispose before you release your last reference to the Image. Otherwise, the resources it is using will not be freed until the garbage collector calls the Image object's Finalize method."

提交回复
热议问题