Citation:
A MATLAB handle class can define a delete method that behaves very much like a destructor in languages like C++ (Figures 3a and 3b). In MATLAB, a delete method is called just before an object is destroyed because the object can no longer be accessed from any MATLAB variable. The delete method can be used to close a file, close an external application, or notify another object that needs to react to the destruction of the first object. It is defined by the handle class, and only handle classes have destructors in MATLAB. This is because MATLAB uses the handle class to represent tangible objects and objects with unique identities. Conceptual objects never really cease to exist—for example, the number 5 doesn't cease to exist because it is no longer held within a variable.