event.listener - Class defining listener objects - MATLAB (original) (raw)

You can create listener object using the event.listener class constructor, or using the handle class addlistener or listener method.

When you create a listener using addlistener, the event source object holds a reference to the listener. When the source is destroyed, MATLAB also destroys the listener. You do not need to store a reference to the listener object to manage its lifecycle.

When you create a listener using event.listener or the listener method, the listener's lifecycle is not coupled to the event source. Because the event source object does not hold a reference to the listener, you have more control over the listener lifecycle. However, if the listener object goes out of scope, the listener no longer exists.

For more information on listener lifecycle, see Listener Lifecycle.