Interview Questions

What is a difference between free and destroy?

Delphi Interview Questions


(Continued from previous question...)

What is a difference between free and destroy?

If you write your own code to instantiate objects, you are responsible for disposing of them as well. Every object inherits a Destroy method (called a destructor) from TObject. To destroy an object, however, you should call the Free method (also inherited from TObject), because Free checks for a nil reference before calling Destroy. For example,

Employee.Free;
destroys the Employee object and deallocates its memory.

(Continued on next question...)

Other Interview Questions