About GC and garbage recovery (gcmarshal)
I recently made a plug-in software. It is required to be suspended for three or four days, so no error will be reported. The process was successful at the beginning, and all the steps were OK. However, when the test runs, the memory will increase by several Mb after a Task is run. I started a test machine for a day, and the memory continued to leak, without any signs of stopping. The 4G memory of the test machine is basically finished. The C ++ component that should be called has not released resources. This problem lasted for two weeks. During this period, various methods were tried. GC and Marshal were used, but it was still fruitless. Finally, I used a stupid method. Instead of deliberately creating those objects, I used an object all the time and ran it for a single object. After the test, I found that the memory was normal and there was a normal recycle.
To be honest, I still believe in. NET GC and still think it is reliable, but in the face of Memory leakage, these are all floating clouds. GC cannot manage them (these naughty guys). I tried to use Marshal to release the handle, and the results were the same. Whether it was created by COM or others, it has been growing.
Either Dispose or Destroy, or Close can be used. In fact, I also set the object to null. In the end, no matter whether it is other or GC. Remind yourself that, although. NET is secure and GC is reliable, it is important to pay attention to memory. I am helpless to the memory of C ++. Many people say who created and who released it, but for some encapsulated components, it is difficult to start with Memory leakage. In fact, the managed object, as long as you do not write too much water, GC is still very powerful, at least the compiler has done processing when compiling into IL. Of course, if you have a definite understanding of garbage collection, you can build a project to monitor your memory and understand it exactly. Reading a hundred times of books is not as effective as testing.