Comments (6)
Thanks @stesie.
This is an interesting one, because I fixed the opposite problem recently. Objects returned to Javascript were being garbage collected by PHP, which in turn caused a seg fault to occur when the objects were accessed or methods called from JS.
Does your Pull Request fix this one, or is it still an issue?
from v8js.
No, the pull request does address another issue.
My theory about this particular issue currently is (once more I'm still not very much into the topic, just gdb'ed around some time), that the problem lies in php_v8js_hash_to_jsobj
, where a v8::FunctionTemplate
is created for each and every object passed back, which is used to create the actual JavaScript object in turn. However the FunctionTemplate persists and subsequent calls lead to further function templates.
I wonder (but have not yet had the time to try out and test further) if a function template should be created only once per class (e.g. based on its name) and reused for subsequent calls to create object instances.
from v8js.
Just to let you know, that I'm working on the topic: stesie@678bd1f
... still needs some more work, but I'll follow up :-)
So far it's without all the v8::Isolate fluff, since it doesn't work reliably wrt. memory leak monitoring
For the moment the snippet from above doesn't seem to leak memory on JS side, at least the GC Trace log does tell so. But still it leaks memory if you monitor the memory usage of the PHP process, hence probably on PHP side. I assume that there's still a flaw with the Z_ADDREF_P
call introduced with issue #6, which adds a reference on the PHP object but never releases it. I assume we need to wrap the freshly created object in a v8::Persistent, make it weak and attach a callback that releases the reference on the PHP object, once the associated JS object is garbage collected.
from v8js.
This looks really good.
Question: is it necessary to keep the FunctionTemplate after NewInstance has been called? If not then the quick fix here could be to free the FunctionTemplate after it is used to create a new instance.
Good point re. the Z_ADDREF_P fix. The solution you've proposed sounds spot on, and should fix the memory leak caused there.
from v8js.
@beest I think you cannot dispose a FunctionTemplate. The handle is passed back as a v8::Local hence there is no Dispose method. After all you can't get rid of created functions as well, they always live until the end of the context.
from v8js.
I'm closing this issue myself in favour of the pull request I just filed.
from v8js.
Related Issues (20)
- Trying to compile with php8 branch on ubuntu 22, getting error: could not determine libv8 version (v8 compiled succesfully) HOT 3
- Dynamic Properties deprecation in PHP 8.2 HOT 4
- Broken build on PHP 8.0.x HOT 2
- Segmentation fault - possibly another GC issue? HOT 7
- Compromise between FORCE_ARRAY and standard setup HOT 8
- sandbox error with v8 11.1.277.13 HOT 1
- libv8 must be version 9.0 or greater (using dockerfile) HOT 1
- Issue running make in ubuntu 22.04 HOT 2
- windows php 8.1
- compile error with g++ 13: error: expected unqualified-id before '&' token
- With wich version of V8 this php library work ? HOT 4
- Error installing on debian 11
- This LIB is very hard to install ! HOT 14
- PROHIBITS_OVERWRITING removed from V8 and causing V8Js compile error. HOT 1
- V8Js 3.0.0 HOT 1
- Is the latest recommended release 2.1.1 or 2.1.2? HOT 4
- Do I have permission to refactor this? HOT 3
- Compilation error: "no matching function for call to 'v8::ObjectTemplate::SetAccessor" HOT 6
- Linux arm64 support? HOT 3
- Is there an official installation tutorial for the v8js extension? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v8js.