listener object not destroyed
조회 수: 3 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
Sai Veeramachaneni
2020년 3월 17일
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
Harry Dymond
2020년 7월 4일
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.
Stefanie Schwarz
2020년 8월 11일
You can also check the following MATLAB Answers Post by the MathWorks Tech Support Team:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!