Destroy cycles that reference player for faster collection

This commit is contained in:
Shoghi Cervantes 2015-06-19 13:31:29 +02:00
parent b166628940
commit f7e6246dc2
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
4 changed files with 31 additions and 14 deletions

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);