From 7edfa3713b892ebd516f225f9b4fad850e72e998 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 3 Dec 2020 19:46:23 +0000 Subject: [PATCH] Do not persist SimpleChunkManager between async tasks this is just asking for memory leaks. --- src/world/generator/GeneratorRegisterTask.php | 4 +--- src/world/generator/PopulationTask.php | 4 +--- src/world/generator/ThreadLocalGeneratorContext.php | 12 +++++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/world/generator/GeneratorRegisterTask.php b/src/world/generator/GeneratorRegisterTask.php index 62958b60d..79957df50 100644 --- a/src/world/generator/GeneratorRegisterTask.php +++ b/src/world/generator/GeneratorRegisterTask.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\world\generator; use pocketmine\scheduler\AsyncTask; -use pocketmine\world\SimpleChunkManager; use pocketmine\world\World; use function igbinary_serialize; use function igbinary_unserialize; @@ -59,12 +58,11 @@ class GeneratorRegisterTask extends AsyncTask{ } public function onRun() : void{ - $manager = new SimpleChunkManager($this->worldHeight); /** * @var Generator $generator * @see Generator::__construct() */ $generator = new $this->generatorClass($this->seed, igbinary_unserialize($this->settings)); - ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $manager), $this->worldId); + ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $this->worldHeight), $this->worldId); } } diff --git a/src/world/generator/PopulationTask.php b/src/world/generator/PopulationTask.php index 8c6c22dc6..377acc34e 100644 --- a/src/world/generator/PopulationTask.php +++ b/src/world/generator/PopulationTask.php @@ -78,7 +78,7 @@ class PopulationTask extends AsyncTask{ return; } $generator = $context->getGenerator(); - $manager = $context->getChunkManager(); + $manager = new SimpleChunkManager($context->getWorldHeight()); /** @var Chunk[] $chunks */ $chunks = []; @@ -124,8 +124,6 @@ class PopulationTask extends AsyncTask{ foreach($chunks as $i => $c){ $this->{"chunk$i"} = $c->isDirty() ? FastChunkSerializer::serializeWithoutLight($c) : null; } - - $manager->cleanChunks(); } public function onCompletion() : void{ diff --git a/src/world/generator/ThreadLocalGeneratorContext.php b/src/world/generator/ThreadLocalGeneratorContext.php index 9a240f501..ebdd8ee27 100644 --- a/src/world/generator/ThreadLocalGeneratorContext.php +++ b/src/world/generator/ThreadLocalGeneratorContext.php @@ -23,8 +23,6 @@ declare(strict_types=1); namespace pocketmine\world\generator; -use pocketmine\world\SimpleChunkManager; - /** * Manages thread-local caches for generators and the things needed to support them */ @@ -49,15 +47,15 @@ final class ThreadLocalGeneratorContext{ /** @var Generator */ private $generator; - /** @var SimpleChunkManager */ - private $chunkManager; + /** @var int */ + private $worldHeight; - public function __construct(Generator $generator, SimpleChunkManager $chunkManager){ + public function __construct(Generator $generator, int $worldHeight){ $this->generator = $generator; - $this->chunkManager = $chunkManager; + $this->worldHeight = $worldHeight; } public function getGenerator() : Generator{ return $this->generator; } - public function getChunkManager() : SimpleChunkManager{ return $this->chunkManager; } + public function getWorldHeight() : int{ return $this->worldHeight; } }