MATLAB Object-Oriented Programming

(Joyce) #1

When MATLAB Destroys Objects


MATLAB destroys objects in the workspace of a function when the function:



  • Reassigns an object variable to a new value

  • Does not use an object variable for the remainder of a function

  • Function execution ends


When MATLAB destroys an object, it also destroys values stored in the properties of the
object. MATLAB frees computer memory associated with the object for use by MATLAB or
the operating system.


You do not need to free memory in handle classes. However, there can be other operations
that you want to perform when destroying an object. For example, closing a file or
shutting down an external program that the object constructor started. Define a delete
method in your handle subclass for these purposes.


See “Handle Class Destructor” on page 7-16 for more information.


See Also


Related Examples



  • “Comparison of Handle and Value Classes” on page 7-2


See Also
Free download pdf