Hey guys. Before creating an issue on github, I wanted to consult you on a possible memory leak I found.
Use case
AWS opened AWS Lambda to support custom platforms, so I wanted to see whether I could get our phalcon application to work. The basic idea of running php in Lambda is that there is a long-running php process with a loop processing requests coming to Lambda, similar to a message queue worker.
The issue
Inside the mentioned loop, the application itself is running. However, I quickly noticed that the Lambda ran out of memory. After reconstructing the setup locally, I noticed that every iteration of bootstrapping phalcon increased the memory usage.
Example
<?php
$oldUsage = 0;
for($i=0; $i<10; $i++) {
$app = new \Phalcon\Mvc\Micro();
$app->get(
'/',
function () {
}
);
$app->handle();
//gc_collect_cycles();
$usage = memory_get_usage() / 1024;
$diff = $usage - $oldUsage;
$oldUsage = $usage;
echo $diff . 'kb<br />';
}
PHP 7.2.20, Phalcon 3.4.4
On my machine, this adds around 8kb of memory every iteration. Adding gc_collect_cycles()
reduces this amount to 0.03kb, but with a more complex application, this amount increases significantly.
Do you have any ideas how to solve this, or should I simply report a bug on github?