Best Practice for Forcing Garbage Collection in C#

前端 未结 15 1832
天命终不由人
天命终不由人 2020-11-22 12:28

In my experience it seems that most people will tell you that it is unwise to force a garbage collection but in some cases where you are working with large objects that don\

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 12:38

    Not sure if it is a best practice, but when working with large amounts of images in a loop (i.e. creating and disposing a lot of Graphics/Image/Bitmap objects), i regularly let the GC.Collect.

    I think I read somewhere that the GC only runs when the program is (mostly) idle, and not in the middle of a intensive loop, so that could look like an area where manual GC could make sense.

提交回复
热议问题