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