MATLAB Object-Oriented Programming

(Joyce) #1

load gong Fs y
gongSound = audioplayer(y,Fs);


The output argument, gongSound, is a handle variable. Calling delete deletes the object
along with the audio source information it contains:


delete(gongSound)


However, the handle variable still exists:


disp(gongSound)


handle to deleted audioplayer


The whos command shows gongSound as an audioplayer object:


whos


Name Size Bytes Class Attributes


Fs 1x1 8 double
gongSound 1x1 0 audioplayer
y 42028x1 336224 double


NoteThe value for Bytes returned by the whos command does not include the data
referenced by a handle because many variables can reference the same data.


The handle gongSound no longer refers to a valid object, as shown by the isvalid
handle method:


isvalid(gongSound)


ans =


logical


0


Calling delete on a deleted handle does nothing and does not cause an error. You can
pass an array containing both valid and invalid handles to delete. MATLAB deletes the
valid handles, but does not issue an error when encountering handles that are already
invalid.


You cannot access properties with the invalid handle variable:


Handle Object Behavior
Free download pdf