47 $entitiesCollected = 0;
49 $memory = memory_get_usage();
51 foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
52 $diff = [count($world->getLoadedChunks()), count($world->getEntities())];
53 $world->doChunkGarbageCollection();
54 $world->unloadChunks(
true);
55 $chunksCollected += $diff[0] - count($world->getLoadedChunks());
56 $entitiesCollected += $diff[1] - count($world->getEntities());
57 $world->clearCache(
true);
60 $cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector();
62 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gc_header()->format(TextFormat::GREEN .
"---- " . TextFormat::RESET, TextFormat::GREEN .
" ----" . TextFormat::RESET));
63 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gc_chunks(TextFormat::RED . number_format($chunksCollected))->prefix(TextFormat::GOLD));
64 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gc_entities(TextFormat::RED . number_format($entitiesCollected))->prefix(TextFormat::GOLD));
66 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gc_cycles(TextFormat::RED . number_format($cyclesCollected))->prefix(TextFormat::GOLD));
67 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gc_memoryFreed(TextFormat::RED . number_format(round((($memory - memory_get_usage()) / 1024) / 1024, 2), 2))->prefix(TextFormat::GOLD));