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

后端 未结 3 833
野性不改
野性不改 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:34

    Why don't you use using keyword. Just encapsulate your Bitmap object in it and Compiler will ensure that Dispose method is called.

    Its simply a syntactic shortcut for

    try
    {
     ...   
    }
    finally
    {
        ...Dispose();
    }
    

提交回复
热议问题