필터 지우기
필터 지우기

addlistener vs. listener

조회 수: 10 (최근 30일)
André
André 2024년 4월 7일
댓글: André 2024년 4월 9일
I understand the differences between listener and addlistener. I don't see much utility there, as I always store my listener in variables or properties.
Still, I can't see a situation where listener is useful and addlistener should not be used. I don't see any case where an object goes out of scope and returns again, other than in parallel processing.
Anyone knows some examples? Or only in parallel processing situations?

답변 (1개)

Pratyush
Pratyush 2024년 4월 8일
Hi Andre,
The distinction between MATLAB's "listener" and "addlistener" functions lies in their use cases related to the lifecycle and management of event listeners:
  • "listener" is suited for creating temporary or anonymous listeners that are automatically destroyed when their source object or event handle goes out of scope. This is useful for short-lived listening scenarios or when listeners should only exist within a specific scope, simplifying memory management.
  • "addlistener" is used for persistent listeners that need explicit management, ideal for long-lived applications or complex UIs where listeners should remain active for the duration of the application or until explicitly removed.
Beyond parallel processing, differences matter in scenarios like modular application design, temporary event monitoring, and resource management. While "addlistener" provides control and explicit management, "listener" offers a simpler approach for automatically managed, scope-bound listeners. The choice between them depends on your application's architecture and resource management needs.
  댓글 수: 1
André
André 2024년 4월 9일
I think you swaped "listener" and "addlistener" in your answer, so I cannot accept it yet.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Events에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by