Destructors in C

Source: Internet
Author: User

Destructors in C #
By Ansil
Introduction
In the enterprise application development world, the buzzwords are Performance, Scalability, and Security. I started my career as a VC ++ programmer, and one fine morning, I was transferred to Web development department. like every C ++ programmer, I also was frustrated. I thought every Tom, Dick, and our very own Harry can program in HTML. but, soon I found that the real challenge is to produce high performance, scalable, and reliable applications. and above all that the loosely coupled, stateless nature of web environment is always going to haunt you.
In order to produce high performance scalable applications, it is important to use your resources in an optimized manner. one tip is that use your resource as late as you can and free it at the earliest after your use. my intention here is to describe the object cleaning up mechanisms used in C #.
Destructors
As we all know, 'struct' are used to destruct instances of classes. When we are using Destructors in C #, we have to keep in mind the following things:
A class can only have one destructor.
Destructors cannot be inherited or overloaded.
Destructors cannot be called. They are invoked automatically.
A destructor does not take modifiers or have parameters.
The following is a declaration of a destructor for the class MyClass :~ MyClass ()
{
// Cleaning up code goes here
}
The programmer has no control on when the destructor is going to be executed because this is determined by the Garbage Collector. the garbage collector checks for objects that are no longer being used by the application. it considers these objects eligible for destruction and reclaims their memory. destructors are also called when the program exits. when a destructor executes what is happening behind the scenes is that the destructor implicitly cballs the Object. finalize method on the object's base class. therefore, the preceding destructor code is implicitly translated to: protected override void Finalize ()

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.