Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.1.5, 1.2.2
-
None
-
None
Description
The actual implementation for UIComponentBase.getFacetsAndChildren() is this:
public Iterator<UIComponent> getFacetsAndChildren()
{ return new _FacetsAndChildrenIterator<UIComponent>(_facetMap, _childrenList); }In most cases there is no children and there is not facets defined, and the creation of this object holds references to facetMap and childrenList iterators, causing possible memory leaks.
The idea is use a similar strategy used in trinidad, avoiding the use of a list and using the compound iterator:
public Iterator<UIComponent> getFacetsAndChildren()
{
// =-=AEW Is this supposed to be an immutable Iterator?
if (_facets == null)
else
{ if (_children == null) return _facets.values().iterator(); } ArrayList<UIComponent> childrenAndFacets = new ArrayList<UIComponent>();
for(UIComponent facet : _facets.values())
for(UIComponent child : _children)
{ childrenAndFacets.add(child); } if (childrenAndFacets.isEmpty())
return _EMPTY_UICOMPONENT_ITERATOR;
return childrenAndFacets.iterator();
}
also on _FacetsAndChildrenIterator use something like this:
public boolean hasNext()
{
boolean hasNext = (_facetsIterator != null && _facetsIterator.hasNext()) ||
(_childrenIterator != null && _childrenIterator.hasNext());
if (!hasNext)
return hasNext;
}
Before hasNext() returns false, set the references to the iterators to null, since this references no longer be used after this;
Also create a class _EmptyIterator<E> to reuse this like trinidad does.