Delphi's object Logoff method destroy and free

Source: Internet
Author: User

When you have finished using the object, you should undo it in time to free up the memory that this object occupies. You can revoke your object by invoking a logout method, which frees the memory allocated to the object.

There are two ways to unregister Delphi: Destroy and free. Delphi recommends using free because it is more secure than destroy, and calling free will produce more efficient code.

You can use the following statements to release an exhausted employee object:

Employee.free;

As with the Create method, the free method is Temployee inherited from the TObject. Putting your logoff in the finally part of the Try...finally program module, and putting the object's program code in the Try section is a good habit of programming. This will ensure that the memory you allocate for this object will be freed, even if the exception occurs when your program code is using the object.

The difference is that Destroy will directly release the object, and free will actually check if the object exists, and if the object exists, or if the object is not nil, it will call Destroy. Therefore, the procedure should be
It is safer to use free to dispose of objects as much as possible. (note, however, that free does not automatically set the object to nil, so after you call free, it is better to manually set the object to nil.) )
The TObject class has a virtual destroy imaginary function and a non-virtual free function. Destroy is called in the free function. Therefore, when we call on any object (which is a subclass object of TObject). Free (), after which the Tobject.free () is executed, and it invokes the destructor of the object we are using Destroy ();. This ensures that any type of object can be properly deconstructed

http://blog.csdn.net/zang141588761/article/details/59480978

Delphi's object Logoff method destroy and free

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.