Fixed PHP-Powered memory leaks

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-26 22:00:34 +01:00
parent 1f8939da6e
commit 895e001216
4 changed files with 15 additions and 5 deletions

View File

@ -94,10 +94,12 @@ class EntityAPI{
public function remove($eid){ public function remove($eid){
if(isset($this->server->entities[$eid])){ if(isset($this->server->entities[$eid])){
$entity = $this->server->entities[$eid]; $entity = $this->server->entities[$eid];
$this->server->entities[$eid] = null;
unset($this->server->entities[$eid]); unset($this->server->entities[$eid]);
$entity->closed = true; $entity->closed = true;
$this->server->query("DELETE FROM entities WHERE EID = ".$entity->eid.";"); $this->server->query("DELETE FROM entities WHERE EID = ".$entity->eid.";");
$this->server->api->dhandle("entity.remove", $entity); $this->server->api->dhandle("entity.remove", $entity);
$entity = null;
unset($entity); unset($entity);
} }
} }

View File

@ -220,13 +220,15 @@ class PlayerAPI{
public function remove($CID){ public function remove($CID){
if(isset($this->server->clients[$CID])){ if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID]; $player = $this->server->clients[$CID];
$this->server->clients[$CID] = null;
unset($this->server->clients[$CID]); unset($this->server->clients[$CID]);
$player->close(); $player->close();
$this->saveOffline($player->username, $player->data); $this->saveOffline($player->username, $player->data);
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';"); $this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
unset($player->entity->player); $player->entity->player = null;
unset($player->entity); $player->entity = null;
$this->server->api->entity->remove($player->eid); $this->server->api->entity->remove($player->eid);
$player = null;
unset($player); unset($player);
} }
} }

View File

@ -113,7 +113,10 @@ class Player{
"status" => 1, "status" => 1,
)); ));
$this->dataPacket(MC_DISCONNECT); $this->dataPacket(MC_DISCONNECT);
$this->buffer = null;
unset($this->buffer);
$this->queue = null;
unset($this->queue);
$this->connected = false; $this->connected = false;
if($msg === true){ if($msg === true){
$this->server->api->chat->broadcast($this->username." left the game"); $this->server->api->chat->broadcast($this->username." left the game");
@ -287,6 +290,7 @@ class Player{
array_unshift($this->queue, array(0, $this->buffer[$data[2]][0], $this->buffer[$data[2]][1], $data[2])); array_unshift($this->queue, array(0, $this->buffer[$data[2]][0], $this->buffer[$data[2]][1], $data[2]));
} }
$this->counter[2] = $data[2]; $this->counter[2] = $data[2];
$this->buffer[$data[2]] = null;
unset($this->buffer[$data[2]]); unset($this->buffer[$data[2]]);
if(isset($data[3])){ if(isset($data[3])){
@ -295,6 +299,7 @@ class Player{
array_unshift($this->queue, array(0, $this->buffer[$data[3]][0], $this->buffer[$data[3]][1], $data[3])); array_unshift($this->queue, array(0, $this->buffer[$data[3]][0], $this->buffer[$data[3]][1], $data[3]));
} }
$this->counter[2] = $data[3]; $this->counter[2] = $data[3];
$this->buffer[$data[3]] = null;
unset($this->buffer[$data[3]]); unset($this->buffer[$data[3]]);
} }
break; break;

View File

@ -582,10 +582,10 @@ class PocketMinecraftServer{
$add = ""; $add = "";
$chcnt = $this->scheduleCnt++; $chcnt = $this->scheduleCnt++;
if($repeat === false){ if($repeat === false){
$add = ' unset($this->schedule['.$chcnt.']);'; $add = '$this->schedule['.$chcnt.']=null;unset($this->schedule['.$chcnt.']);';
} }
$this->schedule[$chcnt] = array($callback, $data, $eventName); $this->schedule[$chcnt] = array($callback, $data, $eventName);
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$chcnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$chcnt.']);return false;} return call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat); $this->action(50000 * $ticks, '$schedule=$this->schedule['.$chcnt.'];'.$add.'if(!is_callable($schedule[0])){$this->schedule['.$chcnt.']=null;unset($this->schedule['.$chcnt.']);return false;}return call_user_func($schedule[0],$schedule[1],$schedule[2]);', (bool) $repeat);
return $chcnt; return $chcnt;
} }
@ -636,6 +636,7 @@ class PocketMinecraftServer{
public function deleteEvent($id){ public function deleteEvent($id){
$id = (int) $id; $id = (int) $id;
$this->events[$id] = null;
unset($this->events[$id]); unset($this->events[$id]);
$this->query("DELETE FROM events WHERE ID = ".$id.";"); $this->query("DELETE FROM events WHERE ID = ".$id.";");
} }