Skip to content

Commit

Permalink
Merge pull request #84 from lucasnetau/master
Browse files Browse the repository at this point in the history
Remove event listeners on pool/worker termination to remove circular references to callbacks
  • Loading branch information
WyriHaximus authored Mar 19, 2023
2 parents bb57368 + 62feea0 commit 1ad9bc8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions benchmark/memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function show_memory($message = '')
$timer = $loop->addPeriodicTimer(0.0001, function () use (&$i, $messenger, &$timer, $loop) {
if ($i >= I) {
$loop->cancelTimer($timer);
$timer = null;
$messenger->terminate();

show_memory('Completed messaging');
Expand All @@ -61,6 +62,6 @@ function show_memory($message = '')

show_memory('Removed loop');

gc_collect_cycles();
$cycles = gc_collect_cycles();

show_memory('gc_collect_cycles');
show_memory('gc_collect_cycles: ' . $cycles);
1 change: 1 addition & 0 deletions src/Pool/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function terminate(Message $message = null, $timeout = 5, $signal = null)
}

return \WyriHaximus\React\timedPromise($this->loop, $timeout)->then(function () {
$this->manager->removeAllListeners();
return $this->manager->terminate();
});
}
Expand Down
1 change: 1 addition & 0 deletions src/Pool/Flexible.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function terminate(Message $message = null, $timeout = 5, $signal = null)
}

return \WyriHaximus\React\timedPromise($this->loop, $timeout)->then(function () {
$this->manager->removeAllListeners();
return $this->manager->terminate();
});
}
Expand Down
1 change: 1 addition & 0 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function terminate()
{
$this->busy = true;
$this->emit('terminating', [$this]);
$this->messenger->removeAllListeners();
return $this->messenger->softTerminate();
}
}

0 comments on commit 1ad9bc8

Please sign in to comment.