CaptionChangeListener Bug?

Hi,

I am not sure if this is really a bug, but I think the CaptionChangeListener class in the AbstractSelect component has a memory leak. It has a List of captionChangeNotifiers in which elements are stored that are being added to the select box. In the AbstractSelect#paint() method CaptionChangeListener#clear() is called. In there an iteration over the captionChangeNotifiers is performed and a remove() is called so that the CaptionChangeListener is no longer registered as a Listener on the CaptionChangeNotifier. So far so good.
What I miss is a final call to List#clear() on the captionChangeNotifiers List. To me it looks as if in that list all elements that have ever been in the Select will remain there forever.

For a better understanding here is a summary of the class with my comments added:

public abstract class AbstractSelect extends AbstractField implements ...
    protected class CaptionChangeListener... {
        // the list in question
        HashSet captionChangeNotifiers = new HashSet();

        public void addNotifierForItem(Object itemId) {
            switch (getItemCaptionMode()) {
                    ... (some magic I do not fully understand was removed. However: I see this...)
                    captionChangeNotifiers.add(i);
            }
        }

        public void clear() {
            for (Iterator it = captionChangeNotifiers.iterator(); it.hasNext();) {
                Object notifier = it.next();
                if (notifier instanceof Item.PropertySetChangeNotifier) {
                    // ok deregister myself as a listener. That makes sense  
                    ((Item.PropertySetChangeNotifier) notifier)
                            .removeListener(getCaptionChangeListener());
                } else {
                    // ok deregister myself as a listener. That makes sense
                    ((Property.ValueChangeNotifier) notifier)
                            .removeListener(getCaptionChangeListener());
                }
                // well why not calling clear on captionChangeNotifiers here?
            }
        }

    ...

    }

Anything I oversaw here?

Greetings
Peer

I agree this is a bug - this listener should not keep old items in memory unnecessarily.

Created
ticket 5149
and fixed.

:V [BUG]

There goes one mor bug!

Thanks for fixing. :smiley:

Greetings
Peer