Do not persist SimpleChunkManager between async tasks

this is just asking for memory leaks.
This commit is contained in:
Dylan K. Taylor 2020-12-03 19:46:23 +00:00
parent dde2e7e66f
commit 7edfa3713b
3 changed files with 7 additions and 13 deletions

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\world\generator; namespace pocketmine\world\generator;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use pocketmine\world\SimpleChunkManager;
use pocketmine\world\World; use pocketmine\world\World;
use function igbinary_serialize; use function igbinary_serialize;
use function igbinary_unserialize; use function igbinary_unserialize;
@ -59,12 +58,11 @@ class GeneratorRegisterTask extends AsyncTask{
} }
public function onRun() : void{ public function onRun() : void{
$manager = new SimpleChunkManager($this->worldHeight);
/** /**
* @var Generator $generator * @var Generator $generator
* @see Generator::__construct() * @see Generator::__construct()
*/ */
$generator = new $this->generatorClass($this->seed, igbinary_unserialize($this->settings)); $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);
} }
} }

View File

@ -78,7 +78,7 @@ class PopulationTask extends AsyncTask{
return; return;
} }
$generator = $context->getGenerator(); $generator = $context->getGenerator();
$manager = $context->getChunkManager(); $manager = new SimpleChunkManager($context->getWorldHeight());
/** @var Chunk[] $chunks */ /** @var Chunk[] $chunks */
$chunks = []; $chunks = [];
@ -124,8 +124,6 @@ class PopulationTask extends AsyncTask{
foreach($chunks as $i => $c){ foreach($chunks as $i => $c){
$this->{"chunk$i"} = $c->isDirty() ? FastChunkSerializer::serializeWithoutLight($c) : null; $this->{"chunk$i"} = $c->isDirty() ? FastChunkSerializer::serializeWithoutLight($c) : null;
} }
$manager->cleanChunks();
} }
public function onCompletion() : void{ public function onCompletion() : void{

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace pocketmine\world\generator; namespace pocketmine\world\generator;
use pocketmine\world\SimpleChunkManager;
/** /**
* Manages thread-local caches for generators and the things needed to support them * Manages thread-local caches for generators and the things needed to support them
*/ */
@ -49,15 +47,15 @@ final class ThreadLocalGeneratorContext{
/** @var Generator */ /** @var Generator */
private $generator; private $generator;
/** @var SimpleChunkManager */ /** @var int */
private $chunkManager; private $worldHeight;
public function __construct(Generator $generator, SimpleChunkManager $chunkManager){ public function __construct(Generator $generator, int $worldHeight){
$this->generator = $generator; $this->generator = $generator;
$this->chunkManager = $chunkManager; $this->worldHeight = $worldHeight;
} }
public function getGenerator() : Generator{ return $this->generator; } public function getGenerator() : Generator{ return $this->generator; }
public function getChunkManager() : SimpleChunkManager{ return $this->chunkManager; } public function getWorldHeight() : int{ return $this->worldHeight; }
} }