//-----------------------------------------------------------------------
 void OverlayProfileSessionListener::finializeSession()
 {
     OverlayContainer* container = dynamic_cast<OverlayContainer*>(mProfileGui);
     if (container)
     {
         OverlayContainer::ChildIterator children = container->getChildIterator();
         while (children.hasMoreElements())
         {
             OverlayElement* element = children.getNext();
             OverlayContainer* parent = element->getParent();
             if (parent) parent->removeChild(element->getName());
             OverlayManager::getSingleton().destroyOverlayElement(element);
         }
     }
     if(mProfileGui)
         OverlayManager::getSingleton().destroyOverlayElement(mProfileGui);
     if(mOverlay)
         OverlayManager::getSingleton().destroy(mOverlay);           
         
     mProfileBars.clear();
 }
    //-----------------------------------------------------------------------
    void Profiler::setEnabled(bool enabled) 
	{
        if (!mInitialized && enabled) 
		{
            // the user wants to enable the Profiler for the first time
            // so we initialize the GUI stuff
            initialize();
            mInitialized = true;
        }
        else
        {
            OverlayContainer* container = dynamic_cast<OverlayContainer*>(mProfileGui);
			if (container)
			{
				OverlayContainer::ChildIterator children = container->getChildIterator();
				while (children.hasMoreElements())
				{
                    OverlayElement* element = children.getNext();
                    OverlayContainer* parent = element->getParent();
                    if (parent) parent->removeChild(element->getName());
                    OverlayManager::getSingleton().destroyOverlayElement(element);
				}
			}
            if(mProfileGui)
                OverlayManager::getSingleton().destroyOverlayElement(mProfileGui);
            if(mOverlay)
                OverlayManager::getSingleton().destroy(mOverlay);			
			
			mProfileBars.clear();
            mInitialized = false;
			mEnabled = false;
        }
        // We store this enable/disable request until the frame ends
        // (don't want to screw up any open profiles!)
        mNewEnableState = enabled;
    }