diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index 15ffec5df..9c6eb50ed 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -48,6 +48,7 @@ class MemoryManager{ private $garbageCollectionAsync; private $chunkLimit; + private $chunkCollect; private $chunkTrigger; private $chunkCache; @@ -71,6 +72,7 @@ class MemoryManager{ $this->garbageCollectionAsync = (bool) $this->server->getProperty("memory.garbage-collection.collect-async-worker", true); $this->chunkLimit = (int) $this->server->getProperty("memory.max-chunks.trigger-limit", 12000); + $this->chunkCollect = (bool) $this->server->getProperty("memory.max-chunks.trigger-chunk-collect", true); $this->chunkTrigger = (bool) $this->server->getProperty("memory.max-chunks.low-memory-trigger", true); $this->chunkCache = (bool) $this->server->getProperty("memory.world-caches.disable-chunk-cache", true); @@ -100,6 +102,12 @@ class MemoryManager{ } } + if($this->chunkTrigger and $this->chunkCollect){ + foreach($this->server->getLevels() as $level){ + $level->doChunkGarbageCollection(); + } + } + $ev = new LowMemoryEvent($memory, $limit, $global, $triggerCount); $this->server->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 83b6f3a5f..74f4c34da 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1707,10 +1707,6 @@ class Server{ $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doAutoSave"]), $this->getProperty("ticks-per.autosave", 6000), $this->getProperty("ticks-per.autosave", 6000)); } - if($this->getProperty("chunk-gc.period-in-ticks", 600) > 0){ - $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doLevelGC"]), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600)); - } - $this->enablePlugins(PluginLoadOrder::POSTWORLD); $this->start(); @@ -2223,12 +2219,6 @@ class Server{ } } - public function doLevelGC(){ - foreach($this->getLevels() as $level){ - $level->doChunkGarbageCollection(); - } - } - public function sendUsage(){ if($this->lastSendUsage instanceof SendUsageTask){ if(!$this->lastSendUsage->isGarbage()){ //do not call multiple times diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index 39fef54bd..8400fa971 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -56,6 +56,10 @@ memory: max-chunks: #Limit of chunks to load per player, overrides chunk-sending.max-chunks trigger-limit: 96 + + #Do chunk garbage collection on trigger + trigger-chunk-collect: true + #Trigger on low memory low-memory-trigger: true @@ -117,9 +121,6 @@ chunk-generation: #Max. amount of chunks in the waiting queue to be populated population-queue-size: 2 -chunk-gc: - period-in-ticks: 600 - ticks-per: animal-spawns: 400 monster-spawns: 1