listener object not destroyed

6 visualizaciones (últimos 30 días)
Mathijs Verhaeghe
Mathijs Verhaeghe el 11 de Mzo. de 2020
Respondida: Stefanie Schwarz el 11 de Ag. de 2020
I have a question about the class handle.addListener.
I understood that an object of this class is destroyed when the source event object is destroyed. If you look to the code below, one should expect that 'v' returns a 'handle to a deleted Listener'. Is my reasoning wrong, or is there a flaw somewhere else?

Respuestas (2)

Sai Veeramachaneni
Sai Veeramachaneni el 17 de Mzo. de 2020
addlistener method returns object of type listener. In the documentation of handle.listener it is specified that
The listener method does not bind the listener's lifecycle to the object that is the source of the event. Destroying the event source object does not affect the lifecycle of the listener object.
Hence it is not expected to destroy listener object when source object is deleted.
  1 comentario
Harry Dymond
Harry Dymond el 4 de Jul. de 2020
But the OP used the function addlistener, not listener.
addlistener is supposed to create a listener whose lifecycle is bound to the object being listened to. From the first page you linked:
"addlistener ties the listener's lifecycle to the object that is the source of the event."
"addlistener creates a coupling between the listener and event source object. The listener object persists until you delete it or until the event object is destroyed. When the event source object is destroyed, MATLAB® automatically destroys the listener object."
So, unless I'm missing something, the OP's example is a bug in that the behaviour directly contravenes the expected documented behaviour.

Iniciar sesión para comentar.


Stefanie Schwarz
Stefanie Schwarz el 11 de Ag. de 2020

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by