From f7e6246dc21306e3633c2f8f8ea7a4672734b22d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 19 Jun 2015 13:31:29 +0200 Subject: [PATCH] Destroy cycles that reference player for faster collection --- src/pocketmine/MemoryManager.php | 5 ++-- src/pocketmine/Player.php | 8 ++++++ src/pocketmine/inventory/BaseInventory.php | 5 ++++ src/pocketmine/permission/PermissibleBase.php | 27 ++++++++++--------- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index e0ea52815..318bc4d12 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -262,8 +262,7 @@ class MemoryManager{ } public function dumpServerMemory($outputFolder, $maxNesting, $maxStringSize){ - gc_enable(); - gc_collect_cycles(); //Cleanup counts + gc_disable(); if(!file_exists($outputFolder)){ mkdir($outputFolder, 0777, true); @@ -347,6 +346,8 @@ class MemoryManager{ echo "[Dump] Finished!\n"; + gc_enable(); + $this->server->forceShutdown(); } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 34fd4fc14..eb6d12014 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2911,8 +2911,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($this->perm !== null){ $this->perm->clearPermissions(); + $this->perm = null; } + if($this->inventory !== null){ + $this->inventory = null; + $this->currentTransaction = null; + } + + $this->chunk = null; + $this->server->removePlayer($this); } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 1491c62fc..4a749b3c3 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -78,6 +78,11 @@ abstract class BaseInventory implements Inventory{ $this->setContents($items); } + public function __destruct(){ + $this->holder = null; + $this->slots = []; + } + public function getSize(){ return $this->size; } diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index bb394bde3..fdcf4b8c0 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -31,7 +31,7 @@ class PermissibleBase implements Permissible{ private $opable = null; /** @var Permissible */ - private $parent; + private $parent = null; /** * @var PermissionAttachment[] @@ -50,11 +50,14 @@ class PermissibleBase implements Permissible{ $this->opable = $opable; if($opable instanceof Permissible){ $this->parent = $opable; - }else{ - $this->parent = $this; } } + public function __destruct(){ + $this->parent = null; + $this->opable = null; + } + /** * @return bool */ @@ -130,7 +133,7 @@ class PermissibleBase implements Permissible{ throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } - $result = new PermissionAttachment($plugin, $this->parent); + $result = new PermissionAttachment($plugin, $this->parent !== null ? $this->parent : $this); $this->attachments[spl_object_hash($result)] = $result; if($name !== null and $value !== null){ $result->setPermission($name, $value); @@ -168,12 +171,12 @@ class PermissibleBase implements Permissible{ $this->clearPermissions(); $defaults = Server::getInstance()->getPluginManager()->getDefaultPermissions($this->isOp()); - Server::getInstance()->getPluginManager()->subscribeToDefaultPerms($this->isOp(), $this->parent); + Server::getInstance()->getPluginManager()->subscribeToDefaultPerms($this->isOp(), $this->parent !== null ? $this->parent : $this); foreach($defaults as $perm){ $name = $perm->getName(); - $this->permissions[$name] = new PermissionAttachmentInfo($this->parent, $name, null, true); - Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent); + $this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, null, true); + Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this); $this->calculateChildPermissions($perm->getChildren(), false, null); } @@ -186,11 +189,11 @@ class PermissibleBase implements Permissible{ public function clearPermissions(){ foreach(array_keys($this->permissions) as $name){ - Server::getInstance()->getPluginManager()->unsubscribeFromPermission($name, $this->parent); + Server::getInstance()->getPluginManager()->unsubscribeFromPermission($name, $this->parent !== null ? $this->parent : $this); } - Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(false, $this->parent); - Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(true, $this->parent); + Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(false, $this->parent !== null ? $this->parent : $this); + Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(true, $this->parent !== null ? $this->parent : $this); $this->permissions = []; } @@ -204,8 +207,8 @@ class PermissibleBase implements Permissible{ foreach($children as $name => $v){ $perm = Server::getInstance()->getPluginManager()->getPermission($name); $value = ($v xor $invert); - $this->permissions[$name] = new PermissionAttachmentInfo($this->parent, $name, $attachment, $value); - Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent); + $this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, $attachment, $value); + Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this); if($perm instanceof Permission){ $this->calculateChildPermissions($perm->getChildren(), !$value, $attachment);