public function resetInstanceCache($className = null)
    {
        if ($className && isset(static::$_aInstanceCache[$className])) {
            unset(static::$_aInstanceCache[$className]);
            return;
        }

        //Get storage key as the class might be aliased.
        $storageKey = Registry::getStorageKey($className);

        if ($className && isset(static::$_aInstanceCache[$storageKey])) {
            unset(static::$_aInstanceCache[$storageKey]);
            return;
        }

        //looping due to possible memory "leak".
        if (is_array(static::$_aInstanceCache)) {
            foreach (static::$_aInstanceCache as $key => $instance) {
                unset(static::$_aInstanceCache[$key]);
            }
        }

        static::$_aInstanceCache = [];
    }