From cc84ec8629f9889f504ea2f6f99f7f5b2f261ff7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 22 Jul 2018 13:41:06 +0100 Subject: [PATCH] Fixed Player/NetworkSession/SessionHandler cycle memory leak NetworkSession and some SessionHandlers hold cyclic refs to each other, stopping them getting destroyed. Unfortunately, these also reference the player, stopping that getting destroyed too. The cycle garbage collector will deal with this, but it's best to get rid of the cyclic refs for immediate collection. --- src/pocketmine/network/mcpe/NetworkSession.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 494d62def..333dace3b 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -228,6 +228,7 @@ class NetworkSession{ } $this->interface->close($this, $notify ? $reason : ""); + $this->disconnectCleanup(); } /** @@ -240,9 +241,16 @@ class NetworkSession{ if($this->connected){ $this->connected = false; $this->player->close($this->player->getLeaveMessage(), $reason); + $this->disconnectCleanup(); } } + private function disconnectCleanup() : void{ + $this->handler = null; + $this->interface = null; + $this->player = null; + } + //TODO: onEnableEncryption() step public function onLoginSuccess() : void{