- edited description
Memory leak?
Does the following code demonstrate a memory leak or do I need to manually do something to clear the timer from memory? On execution you'll see that It takes no time at all to reach the memory limit and error out. Thanks in advance and keep up the good work!
<?php
error_reporting(E_ALL);
ini_set('memory_limit', '32M');
$i = 0;
$startedAt = microtime(TRUE);
$callback = function() use (&$i, $startedAt) {
if (!(++$i % 2500)) {
echo vsprintf("%d\t%d\t%d\t%.4f\t%d\n", $last = [
"job" => $i,
"mem" => memory_get_usage(),
"real" => memory_get_usage(TRUE),
"runtime" => $runtime = (microtime(TRUE) - $startedAt),
"jps" => ceil($i / $runtime)
]);
}
};
while (TRUE) {
$timer = new EvTimer(0, 0, $callback);
Ev::run(Ev::RUN_ONCE | Ev::RUN_NOWAIT);
}
Comments (5)
-
reporter -
repo owner Hmm, looks like Zend MM issue. No leaks with
USE_ZEND_ALLOC=0 php leak.php
. I mean there is a bug somewhere in Ev. I'll check it out. As always, pull requests are welcome. -
repo owner - changed status to resolved
Fixed in branch
develop
.Please checkout the branch. If it's okay, I'll upload new package to PECL. There are some important changes concerning memory management of all watchers. I'd have appreciated it, if you'd run some tests.
Thanks for taking time testing pecl-ev )
-
repo owner Also note, that not all of the timers will fire in your code, because of the
Ev::RUN_NOWAIT
flag.The
EvTimer
object is(should be) destroyed on each iteration of the loop. The messages appearing on screen are the timer events that managed to fire and call their callbacks before the previous value of the$timer
variable is destroyed.Thus, the code probably won't work as expected in the
develop
branch. -
reporter The changes in the
develop
branch appear to have solved this issue, though I'll continue testing over the next couple of days. My C skills are somewhat substandard at this point, though I'm working to remedy that situation so I can contribute to projects like this when I run into issues. In the meantime, thanks for taking care of this particular problem. - Log in to comment