MATLAB Object-Oriented Programming

(Joyce) #1

Handle Class Destructor


In this section...
“Basic Knowledge” on page 7-16
“Syntax of Handle Class Destructor Method” on page 7-16
“Handle Object During delete Method Execution” on page 7-17
“Support Destruction of Partially Constructed Objects” on page 7-18
“When to Define a Destructor Method” on page 7-19
“Destructors in Class Hierarchies” on page 7-20
“Object Lifecycle” on page 7-20
“Restrict Access to Object Delete Method” on page 7-22
“Nondestructor Delete Methods” on page 7-23
“Java Objects Referencing MATLAB Objects” on page 7-23

Basic Knowledge


Class destructor – a method named delete that MATLAB calls implicitly before
destroying an object of a handle class. Also, user-defined code can call delete explicitly
to destroy an object.

Nondestructor – a method named delete that does not meet the syntax requirements of
a valid destructor. Therefore, MATLAB does not call this method implicitly when
destroying handle objects. A method named delete in a value class is not a destructor. A
method named delete in a value class that sets the HandleCompatible attribute to
true is not a destructor.

“Object Lifecycle” on page 7-20

“Method Attributes” on page 9-5

Syntax of Handle Class Destructor Method


MATLAB calls the destructor of a handle class when destroying objects of the class.
MATLAB recognizes a method named delete as the class destructor only if you define
delete as an ordinary method with the appropriate syntax.

7 Value or Handle Class — Which to Use

Free download pdf