About GC and garbage recovery (gcmarshal)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.