Enhance UIComponentBase.getFacetsAndChildren(), creating _FacetsAndChildrenIterator only when it is necessary -------------------------------------------------------------------------------------------------------------
Key: MYFACES-1864 URL: https://issues.apache.org/jira/browse/MYFACES-1864 Project: MyFaces Core Issue Type: Improvement Affects Versions: 1.2.2, 1.1.5 Reporter: Leonardo Uribe Assignee: Leonardo Uribe 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) { if (_children == null) return _EMPTY_UICOMPONENT_ITERATOR; return _children.iterator(); } else { if (_children == null) return _facets.values().iterator(); } ArrayList<UIComponent> childrenAndFacets = new ArrayList<UIComponent>(); for(UIComponent facet : _facets.values()) { childrenAndFacets.add(facet); } 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) { _facetsIterator = null; _childrenIterator = null; } 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. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.