Idisposable. Dispose Method

Source: Internet
Author: User
Tags custom name

If an object's dispose method is called more than once, the object must ignore all calls after the first call. If the dispose method of an object is called multiple times, do not raise an exception. If the instance method except dispose is released, objectdisposedexception is triggered.

You may expect resource types to use specific conventions to indicate the allocated and released statuses. Stream classes are such an example. Traditionally, they are either open or closed. The implementers of classes with such conventions may choose to implement a public method with a custom name (such as "close") to call the dispose method.

Because the dispose method must be called explicitly, the object implementing idisposable must also implement a terminator to handle resource release issues when dispose is not called. By default, the garbage collector automatically calls the final end of an object before it recycles its memory. However, after calling the dispose method, the garbage collector usually does not need to call the terminator of the released object. To prevent automatic termination, the dispose implementation can call the GC. suppressfinalize method.

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.