Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dj committed Aug 11, 2020
1 parent c969b6c commit ab60473
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/MProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function __construct($process = 5, $table_size = -1, $data_size = 1024) {
$this->init();
}

/**
* destroy memory
*/
public function __destruct() {
$this->atomic_table->destroy();
$this->locker->destroy();
}

/**
* init table
*/
Expand All @@ -48,7 +56,6 @@ private function init() {
$this->atomic_table = new Table($this->table_size);
$this->atomic_table->column('id', Table::TYPE_INT, 4);
$this->atomic_table->create();

// lock
$this->locker = new Lock();
}
Expand Down
12 changes: 12 additions & 0 deletions src/QueueTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public function __construct($size, $data_size) {
$this->locker = new Lock(SWOOLE_MUTEX);
}

/**
* destroy memory
*/
public function __destruct() {
$this->max_atomic = NULL;
$this->min_atomic = NULL;
$this->meta_table->destroy();
$this->locker->destroy();
$this->destroy();
}


public function get_size() {
return $this->memorySize + $this->meta_table->memorySize;
}
Expand Down

0 comments on commit ab60473

Please sign in to comment.