Skip to content

Commit 1ad9bc8

Browse files
authored
Merge pull request #84 from lucasnetau/master
Remove event listeners on pool/worker termination to remove circular references to callbacks
2 parents bb57368 + 62feea0 commit 1ad9bc8

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

benchmark/memory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function show_memory($message = '')
3737
$timer = $loop->addPeriodicTimer(0.0001, function () use (&$i, $messenger, &$timer, $loop) {
3838
if ($i >= I) {
3939
$loop->cancelTimer($timer);
40+
$timer = null;
4041
$messenger->terminate();
4142

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

6263
show_memory('Removed loop');
6364

64-
gc_collect_cycles();
65+
$cycles = gc_collect_cycles();
6566

66-
show_memory('gc_collect_cycles');
67+
show_memory('gc_collect_cycles: ' . $cycles);

src/Pool/Fixed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public function terminate(Message $message = null, $timeout = 5, $signal = null)
119119
}
120120

121121
return \WyriHaximus\React\timedPromise($this->loop, $timeout)->then(function () {
122+
$this->manager->removeAllListeners();
122123
return $this->manager->terminate();
123124
});
124125
}

src/Pool/Flexible.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function terminate(Message $message = null, $timeout = 5, $signal = null)
149149
}
150150

151151
return \WyriHaximus\React\timedPromise($this->loop, $timeout)->then(function () {
152+
$this->manager->removeAllListeners();
152153
return $this->manager->terminate();
153154
});
154155
}

src/Worker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function terminate()
7272
{
7373
$this->busy = true;
7474
$this->emit('terminating', [$this]);
75+
$this->messenger->removeAllListeners();
7576
return $this->messenger->softTerminate();
7677
}
7778
}

0 commit comments

Comments
 (0)