<?php
/**
 * 短い説明
 * 
 * 長い説明
 * 
 * @package aowp
 */
/**
 * 短い説明
 * 
 * 長い説明
 * 
 * @package aowp
 */
class AOWP_InstanceReleaseManager {
	private static $_releaseInstanceArray = array();
	
	public static function addReleaseInstance(&$elementInstance) {
		AOWP_InstanceReleaseManager::$_releaseInstanceArray[] = &$elementInstance;
	}
	
	public static function releaseInstance() {
		AOWP_Logger::setStartTime(1000);
		$releasedInstanceCount = 0;
		foreach (AOWP_InstanceReleaseManager::$_releaseInstanceArray as $releaseInstance) {
			if (is_object($releaseInstance) && is_subclass_of($releaseInstance, 'AOWP_PHPElement')) {
				$releasedInstanceCount++;
				$releaseInstance->releaseInstance();
			}
			else if (is_array($releaseInstance)) {
				foreach ($releaseInstance as $oneReleaseInstance) {
					if (is_object($releaseInstance) && is_subclass_of($oneReleaseInstance, 'AOWP_PHPElement')) {
						$releasedInstanceCount++;
						$oneReleaseInstance->releaseInstance();
					}
				}
			}
		}
		AOWP_Logger::logging('[Release instance] ' . $releasedInstanceCount . ' instances are released', 1000);
		AOWP_InstanceReleaseManager::$_releaseInstanceArray = null;
		AOWP_InstanceReleaseManager::$_releaseInstanceArray = array();
	}
}
?>