Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Io/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public function close()
}

$this->emit('close');
/**
* MemoryLeak: Remove all listeners from executor, so it
* will be removed from memory when connection
* is closed.
*/
$this->executor->removeAllListeners();
$this->removeAllListeners();
}

Expand Down
22 changes: 22 additions & 0 deletions src/Io/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ public function isIdle()

public function enqueue($command)
{
/**
* MemoryLeak: Make sure removeAllListeners is called on commands,
* otherwise they might stay in memory for ever.
*/
$command->on(
'error',
function () use ($command) {
$command->removeAllListeners();
}
);
$command->on(
'success',
function () use ($command) {
$command->removeAllListeners();
}
);
$command->on(
'end',
function () use ($command) {
$command->removeAllListeners();
}
);
$this->queue->enqueue($command);
$this->emit('new');

Expand Down