/** * Deattaches the passed synchronizable instance from the registry, destroys it, and * deletes all data from the APCu if no more instances are registered. * * @param \AppserverIo\Synchronizable\SynchronizableInterface $synchronizable The instance to be destroyed * * @return void * @throws \RuntimeException Is thrown if the data can't be deleted from APCu */ public static function destroy(SynchronizableInterface $synchronizable) { // load the serial $serial = $synchronizable->__serial(); // detach the instance Registry::detach($synchronizable); // destroy the instance unset($synchronizable); // check if we've to destroy the data here if (apc_exists($serial) && apc_fetch($serial) === 0 && Registry::hasData($serial)) { $iterator = new \ApcIterator('user', '/^' . $serial . '\\./'); foreach ($iterator as $key => $value) { if (apc_delete($key) === false) { throw new \RuntimeException(sprintf('Can\'t delete property for %s::%s (%s) instance', get_class($synchronizable), $key, $serial)); } } } }