A weak list works pretty identical to the java.util.ArrayList class except that it usually refers its elements using a weak reference. Weak references enable the garbage collector to remove objects though they are still referenced through the weak ref. In this case, the reference returns null (i. e. through the {@link #get(int)} method). Note that the list does not change its size though the references may be garbage-collected. However, if you invoke the {@link #trim} method, 'dead' references are removed.Though the implementation of the java.util.List methods always add the elements as weak references, it is also possible to insert elements as hard references using the {@link #addHardReference(Object)} method, allowing to mix weak and hard references in asingle list. This is e. g. used by the {@link org.openbp.common.listener.ListenerSupport}class, which stores the listeners as weak references, but the listener classes as regular references in order to minimize object allocation. Note the the Iterator returned by the {@link java.util.AbstractList#iterator} method always returnselements that are validly referenced by the list. The references in the list can be copied to a list that contains regular (hard) references using the {@link #createHardList} method.
@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.