When is it acceptable to call GC.Collect?

前端 未结 24 2439
挽巷
挽巷 2020-11-22 08:54

The general advise is that you should not call GC.Collect from your code, but what are the exceptions to this rule?

I can only think of a few very speci

24条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:22

    In your example, I think that calling GC.Collect isn't the issue, but rather there is a design issue.

    If you are going to wake up at intervals, (set times) then your program should be crafted for a single execution (perform the task once) and then terminate. Then, you set the program up as a scheduled task to run at the scheduled intervals.

    This way, you don't have to concern yourself with calling GC.Collect, (which you should rarely if ever, have to do).

    That being said, Rico Mariani has a great blog post on this subject, which can be found here:

    http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx

提交回复
热议问题