/** * Tries to free the given amount of memory * * @param int $size Memory to free in bytes * @return bool Returns if the memory could be freed */ public function freeMemory($size) { $currentMemory = memory_get_usage(TRUE); $freedMemory = 0; $databases = Manager::getIdentifiersByTag(Coordinator::MEMORY_MANAGER_TAG, TRUE); foreach ($databases as $identifier) { Manager::free($identifier); $freedMemory += $currentMemory - memory_get_usage(TRUE); $currentMemory = memory_get_usage(TRUE); if ($freedMemory >= $size) { return TRUE; } // DebugUtility::var_dump(gc_enabled(), array_keys(get_defined_vars()), GeneralUtility::formatBytes($currentMemory), GeneralUtility::formatBytes($freedMemory)); } // DebugUtility::var_dump(gc_enabled(), array_keys(get_defined_vars()), GeneralUtility::formatBytes($currentMemory), GeneralUtility::formatBytes($freedMemory)); return FALSE; }
/** * Drops the database with the given identifier * * @param string $databaseIdentifier Unique identifier of the database * @return void */ public function dropDatabase($databaseIdentifier) { GeneralUtility::assertDatabaseIdentifier($databaseIdentifier); // If the database is in the object store remove it if (Manager::hasObject($databaseIdentifier)) { Manager::free($databaseIdentifier); } if (!$this->databaseExists($databaseIdentifier)) { throw new InvalidDatabaseException(sprintf('Database "%s" does not exist', $databaseIdentifier), 1412525836); } $this->dataWriter->dropDatabase($databaseIdentifier); $this->eventEmitter->emit(Event::DATABASE_DROPPED, array($databaseIdentifier)); }
/** * @test * @expectedException \Cundd\PersistentObjectStore\Memory\Exception\ManagerException */ public function failedFreeTest() { $identifier = 'not-existing-identifier'; Manager::free($identifier); }