private void removeOldChildren()
    {
        Map<String, Object> attributes = component.getAttributes();
        List<String> currentComponents = createdComponents;

        // Get the old list of created component ids and update the current list as a
        // component attribute
        Object oldValue;

        if (currentComponents != null)
        {
            oldValue = attributes.put(JSP_CREATED_COMPONENT_IDS, currentComponents);
            createdComponents = null;
        }
        else
        {
            oldValue = attributes.remove(JSP_CREATED_COMPONENT_IDS);
        }

        // Remove old children that are no longer present
        if (oldValue != null)
        {
            List<String> oldList = TypedCollections.dynamicallyCastList((List)oldValue, String.class);

            int oldCount = oldList.size();

            if (oldCount > 0)
            {
                if (currentComponents != null)
                {
                    int currStartIndex = 0;

                    for (int oldIndex = 0; oldIndex < oldCount; oldIndex++)
                    {
                        String oldId = oldList.get(oldIndex);

                        int foundIndex = _indexOfStartingFrom(currentComponents, currStartIndex, oldId);

                        if (foundIndex != -1)
                        {
                            currStartIndex = foundIndex + 1;
                        }
                        else
                        {
                            UIComponent child = component.findComponent(oldId);
                            // if a component is marked transient, it would have
                            // been already removed from the child list, but the
                            // oldList would still have it.  In addition, the component
                            // might have manually been removed.  So, if findComponent
                            // isn't successful, don't call remove child (it will NPE)
                            if ( child != null)
                            {
                                component.getChildren().remove(child);
                            }
                        }
                    }
                }
                else
                {
                    List<UIComponent> children = component.getChildren();

                    // All old components need to be removed
                    for (String oldId : oldList)
                    {
                        UIComponent child = component.findComponent(oldId);
                        if (child != null)
                        {
                            children.remove(child);
                        }
                    }
                }
            }
        }
    }