This class holds a list of event listeners. It can be used to implement generic listener functionality. It combines listeners of various type into a single 'listener manager' class. Listeners can be added as regular 'hard' references ( {@link #addListener}) or as 'weak' references ( {@link #addWeakListener}), which may be garbage-collected if not referenced otherwise. The add-methods also ensure that the same listener will not be registered twice (comparing the listener objects using the == operation). Listeners that have not been removed from the object they have been registered with are a common cause for memory leaks. By adding them as weak listeners, you may not just add and forget them. They will be automatically garbage-collected if not referenced otherwise and automatically (i. e. after a call to the {@link #getListenerIterator} method) removed fromthe listener list. ATTENTION: Never add an automatic class (i. e new FocusListener () { ... }) or an inner class that is not referenced otherwise as a weak listener to the list. These objects will be cleared by the garbage collector during the next gc run! The listeners and the corresponding listener classes will be stored in a single array list of type {@link WeakArrayList} the listener classes using hard links and the listeners as eitherhard or weak references. The {@link WeakArrayList} class is allocated lazily. This minimizes thefootprint of the ListenerSupport class as long as no listeners have been added. For access to the listeners, you may use the {@link #getListenerIterator} method.It will return a static instance of {@link EmptyIterator} if no listeners of the desired typehave been registered, minimizing allocation overhead. However, if matching listeners have been created, a small-footprint iterator class will be constructed, but this should be tolerable.
@author Heiko Erhardt
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.