C# Timer and memory leak

前端 未结 3 497
既然无缘
既然无缘 2021-01-25 23:06

I am creating a program that will check for directory listing every 2 seconds. I expect this program to run for months without leaking memory or requiring any human interaction.

3条回答
  •  一整个雨季
    2021-01-25 23:28

    1. I am going to assume that you believe there is a leak because your task manager mem usage is going up (which is completely normal). The virtual memory manager is lazy and won't swap out anything unless it needs to. Your GC will clean up anything once a threshold is hit.

    2. The 10000 value is the specified timer interval in milliseconds. As Servy pointed out, you're overwriting it later on so you're accomplishing nothing except maybe getting rid of warnings upon building the project (e.g. uninstantiated object).

提交回复
热议问题