Open
Description
One more whilst you're on a roll :)
I revisited one of the scripts that's now working. Ran it through valgrind and getting 32,000bytes lost with 100 iterations. On more complex scripts it can get pretty hefty. If i return an anonymous class, for example, from my8::getthing(), it's perfectly fine.
<?php
class my8 extends \V8Js
{
public function getthing() {
return function() {
};
}
}
$j = new my8();
for($i = 0; $i < 100; $i++) {
$r = $j->executeString('
(() => {
var a = PHP.getthing()
})();
');
echo "done {$i}\n";
gc_collect_cycles();
}
the output there is:
==944240== HEAP SUMMARY:
==944240== in use at exit: 84,159 bytes in 268 blocks
==944240== total heap usage: 26,314 allocs, 26,046 frees, 16,984,708 bytes allocated
==944240==
==944240== 32,000 bytes in 100 blocks are definitely lost in loss record 44 of 44
==944240== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==944240== by 0x384F1C: __zend_malloc (zend_alloc.c:2975)
==944240== by 0x3D54A2: zend_closure_new (zend_closures.c:484)
==944240== by 0x3B03F8: _object_and_properties_init (zend_API.c:1417)
==944240== by 0x3B03F8: object_init_ex (zend_API.c:1431)
==944240== by 0x3D5A3F: zend_create_closure (zend_closures.c:675)
==944240== by 0x40098A: ZEND_DECLARE_LAMBDA_FUNCTION_SPEC_CONST_UNUSED_HANDLER (zend_vm_execute.h:9509)
==944240== by 0x430062: execute_ex (zend_vm_execute.h:53953)
==944240== by 0x75C395D: xdebug_execute_ex (base.c:376)
==944240== by 0x39FAFE: zend_call_function (zend_execute_API.c:812)
==944240== by 0x7D513BA: v8js_call_php_func(_zend_object*, _zend_function*, v8::FunctionCallbackInfo<v8::Value> const&) (v8js_object_export.cc:158)
==944240== by 0x837273C: ??? (in /usr/local/lib/libv8.so)
==944240== by 0x8371C4A: ??? (in /usr/local/lib/libv8.so)
==944240==
==944240== LEAK SUMMARY:
==944240== definitely lost: 32,000 bytes in 100 blocks
==944240== indirectly lost: 0 bytes in 0 blocks
==944240== possibly lost: 0 bytes in 0 blocks
==944240== still reachable: 52,159 bytes in 168 blocks
==944240== suppressed: 0 bytes in 0 blocks
Somewhere the closure isn't being cleaned up properly, i'd imagine? Been poking around v8js_weak_closure_callback
but not come up with anything as yet.