-
Notifications
You must be signed in to change notification settings - Fork 205
Description
Hey
Came across this one today..it probably leans more towards being a bug, else maybe a documentation thing.
When setExceptionFilter
is used like this:
$v = new \V8Js();
$v->setExceptionFilter(function ($e) { return $e; });
then all is good with the world. However, if you have something like:
class Foo extends \V8Js
{
public function __construct() {
parent::__construct();
$this->setExceptionFilter(function ($e) { return $e; });
}
}
$v = new Foo();
Then you actually get into the situation where the instance isn't destructed when unset (until the script finishes). Changing it to something like:
$this->setExceptionFilter((function ($e) {
return $e;
})->bindTo(null));
does the trick - so presumably the anonymous function is keeping the instance's refcount up.
We came across this one because we (for performance reasons) recycle the instance for ~1000 executions, before explicitly destroying and recreating - because if not, then even this:
$v = new \V8Js();
for ($i = 0; $i < 1500000; $i++) {
$v->executeString('');
}
causes the memory shown on top
to increase.
So I guess two-for-one here:
- setExceptionFilter probs needs something to handle bound anonymous functions
- There is definitely something accumulating over time.
I'll try and have a look over the weekend if I get chance, but perhaps you (or someone else) might have ideas before then.
Hope you're well!
Cheers
Mark