Does a periodic WMI request cause a memory leak?

I am new to .NET programming, and now I am developing a computer system for monitoring the health of a computer, which is now in its infancy. I will use C # 2010 and request computer information using WMI queries.

Before I could continue developing the application, I created a mini-test application to test my classes and its methods. The flow of the test application is as follows:

  • Application launch
  • Enter host name, username and password
  • the query button is pressed and query methods are started.
  • The text box in my user interface is updated by printing the result of the requests.

I have a class called "Machine" that contains properties such as the name of the processor and some properties that can be updated, such as the current CPU usage. In this class, I have 2 main methods: GetStaticSysInfo and GetDynamicSysInfo, where the first method requests system information that does not change over time, and the later method requests information such as CPU and memory usage. I have another method called Refresh that I use to bypass the GetDynamicSysInfo method.

Since I use WPF for my user interface, I used DispatcherTimer to periodically query the machine and print the updated information to a text field in the user interface after clicking the Query button. However, I noticed that every time I called machine.Refresh (), the memory usage in the application increased by several (several hundred KB). I cannot understand what happened to the program, and I would appreciate that someone could give some advice on this.

Please let me know if you need more information or any parts of the code.

Thanks in advance.

EDIT: GC.Collect() Timer_Tick, , , . , . ?

+3
1

, GC.Collect(). , GC . , Collect() 1- 2- , , , , .. .

( ), . GC , GC. .

0

All Articles