         return newVisibleElements;
     }
 
+    /** 
+     *  @private
+     *  If the factory has changed, or is now null, remove and free all the old
+     *  visual elements, if there were any.
+     * 
+     *  @returns True if at least one visual element was removed.
+     */
+    private function discardGridElementsIfFactoryChanged(
+        factory:IFactory,
+        layer:GridLayer,
+        oldVisibleElements:Vector.<IVisualElement>):Boolean    
+    {
+        if (oldVisibleElements.length > 0 &&
+            factory != elementToFactoryMap[oldVisibleElements[0]])
+        {
+            for each (var oldElt:IVisualElement in oldVisibleElements)
+            {
+                layer.removeElement(oldElt);
+                freeGridElement(oldElt);
+            }
+            oldVisibleElements.length = 0;
+            return true;
+        }
+        
+        return false;
+    }
+    
     /** 
      *  @private
      *  Free each member of elements if the corresponding member of oldIndices doesn't 

    private function layoutSelectionIndicators(layer:GridLayer):void
    {
        const selectionIndicatorFactory:IFactory = grid.selectionIndicator;
        
        // TBD(hmuller): if selectionIndicatorFactory has -changed- get rid
        // of the old selection indicators.   See layoutIndicator() for an example
        
        if (!selectionIndicatorFactory)
        {
            clearSelectionIndicators();
            return;
        }
        
        // layout and update visibleSelectionIndicators,Indices
                
        if (isRowSelectionMode())

        
        const newVisibleElementCount:uint = newVisibleIndices.length;
        const newVisibleElements:Vector.<IVisualElement> = new Vector.<IVisualElement>(newVisibleElementCount);

        for (var index:int = 0; index < newVisibleElementCount; index++) 
        {
            var newEltIndex:int = newVisibleIndices[index];
