From 342a74ffcb0a18c3fd54c34c545f30b6add7c8ec Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 7 Nov 2018 20:01:07 +0000 Subject: [PATCH] Level: Collect garbage from chunk internals in doChunkGarbageCollection() --- src/pocketmine/level/Level.php | 1 + src/pocketmine/level/format/Chunk.php | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 5502811dc..fda1e3d2d 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2979,6 +2979,7 @@ class Level implements ChunkManager, Metadatable{ $this->unloadChunkRequest($X, $Z, true); } } + $chunk->collectGarbage(); } $this->provider->doGarbageCollection(); diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index dd6fa64ec..27892f8fb 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -836,18 +836,13 @@ class Chunk{ } /** - * Disposes of empty subchunks + * Disposes of empty subchunks and frees data where possible */ - public function pruneEmptySubChunks(){ + public function collectGarbage() : void{ foreach($this->subChunks as $y => $subChunk){ - if($subChunk instanceof EmptySubChunk){ - continue; - }elseif($subChunk->isEmpty()){ //normal subchunk full of air, remove it and replace it with an empty stub + if(!($subChunk instanceof EmptySubChunk) and $subChunk->isEmpty()){ //normal subchunk full of air, remove it and replace it with an empty stub $this->subChunks[$y] = $this->emptySubChunk; - }else{ - continue; //do not set changed } - $this->hasChanged = true; } }