Skip to content

Memory issues with setExceptionFilter #543

@redbullmarky

Description

@redbullmarky

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:

  1. setExceptionFilter probs needs something to handle bound anonymous functions
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions