How listener's are unregistered ?

In our application we use many listens. We use collection change listener in almost all browse page and many value change listeners. Till now we have not faced any memory leak issue(We have not tested the performance yet). Now we are planning for performance test. Do we need to remove the listeners manually at the time of closing the window or there is any other optimize way to handle this. Please suggest the best approach.



No need to unregister listeners on data sources and UI components in order to achieve better performance. When a window becomes closed it is being detached from a tree of UI components. Since there are no objects that hold references to the window (it is not reachable from GC roots) it will be collected by garbage collector with all nested objects and references.

It is worth mentioning that CUBA entities have listeners which can be added by data sources, but these listeners are stored as WeakReference objects. If you get some entity from a closed window (Editor or Lookup) then these listeners will not prevent garbage collection of the window objects. WeakReferences will be broken and the window with UI components, data sources, and their listeners will be collected by JVM GC.

Please note, if you add listeners directly to an entity you have to hold a reference on these listeners otherwise they will be collected by GC. If you need to track changes of entity properties it is the best practice to add listeners to the data source which contains this entity, in this case you don’t need to hold reference on your listener.

If you conduct performance testing and spot any memory leak problem - it is not normal, please tell us about it.