I have two classes: Plantand Generator. Generatorcreates a vector and passes it through notify(), which Plantlistens. The following are the classes. Please note that I did not include the actual data generation method because it is not relevant to my question.
classdef Plant < handle
properties
Listener
end
methods
function ListenerCallback(obj, data)
end
end
end
classdef Generator < handle
properties
plant
end
events
newSignal
end
methods
function obj = Generator(plant)
obj.plant = plant;
obj.plant.Listener = addlistener(obj, 'newSignal', ...
@(src, data) obj.plant.ListenerCallback(data));
end
function delete(obj)
delete(obj.plant.Listener);
disp('Generator instance deleted');
end
end
end
I noticed that the destructor Generatorbehaves very strange: the first time you create it, then delete the instance Generator, it does not start the destructor until the second time I create the instance Generator. Here is an example:
>> P = Plant
P =
Plant handle
Properties:
Listener: []
Methods, Events, Superclasses
>> G = Generator(P)
G =
Generator handle
Properties:
plant: [1x1 Plant]
Methods, Events, Superclasses
>> clear G
>> G = Generator(P)
Generator instance deleted
G =
Generator handle
Properties:
plant: [1x1 Plant]
Methods, Events, Superclasses
>> clear G
Generator instance deleted
, . , ? ( Plant.ListenerCallback() Generator, .)
EDIT. , clear G, G , Generator P.Listener.Source. . P.Listener, G.. , , ?