History

Work on fixing V8 memory leaks, memory leak test

ksuprynowicz committed 3 years ago

Commit 42704ea1 parent f016a199 files · +46 −3Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp (1 of 9 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+13−0
@@ -146,7 +146,9 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 145 unmodified lines
146146 if (lookupV8 != enginePtr->_qobjectWrapperMapV8.end()) {
147147 enginePtr->_qobjectWrapperMapV8.erase(lookupV8);
148148 }
149+ qDebug() << "ScriptObjectV8Proxy::newQObject object deleted, object count: " << enginePtr->_qobjectWrapperMapV8.size();
149150 });
151+ //qDebug() << "ScriptObjectV8Proxy::newQObject object count: " << engine->_qobjectWrapperMapV8.size();
150152 }
151153
152154 return V8ScriptValue(engine, proxy.get()->toV8Value());
@@ -373,6 +375,10 @@ void ScriptObjectV8Proxy::investigate() { · 220 unmodified lines
373375 v8::Local<v8::Object> propertiesObject = v8::Object::New(_engine->getIsolate());
374376 v8Object->SetInternalField(2, propertiesObject);
375377 _v8Object.Reset(_engine->getIsolate(), v8Object);
378+ if (_ownsObject) {
379+ qDebug(scriptengine_v8) << "ScriptObjectV8Proxy::investigate SetWeak";
380+ _v8Object.SetWeak(this, weakHandleCallback, v8::WeakCallbackType::kParameter);
381+ }
376382
377383 // Add all the methods objects as properties - this allows adding properties to a given method later. Is used by Script.request.
378384 // V8TODO: Should these be deleted when the script-owned object is destroyed? It needs checking if script-owned objects will be garbage-collected, or will self-referencing prevent it.
@@ -383,7 +389,13 @@ void ScriptObjectV8Proxy::investigate() { · 4 unmodified lines
383389 Q_ASSERT(false);
384390 }
385391 }
392+}
386393
394+void ScriptObjectV8Proxy::weakHandleCallback(const v8::WeakCallbackInfo<ScriptObjectV8Proxy>& info) {
395+ //V8TODO: does the object need to be moved to script engine thread?
396+ //V8TODO: why does this never get called?
397+ qDebug(scriptengine_v8) << "ScriptObjectV8Proxy::weakHandleCallback";
398+ info.GetParameter()->_object->deleteLater();
387399 }
388400
389401 QString ScriptObjectV8Proxy::name() const {
@@ -690,6 +702,7 @@ V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V · 300 unmodified lines
690702 //V8TODO ScriptEngine::ExcludeDeleteLater |
691703 ScriptEngine::PreferExistingWrapperObject;
692704 // It's not necessarily new, newQObject looks for it first in object wrapper map
705+ // V8TODO: won't ScriptEngine::ScriptOwnership cause trouble here?
693706 return ScriptObjectV8Proxy::newQObject(_engine, proxy, ScriptEngine::ScriptOwnership, options);
694707 //return _engine->newQObject(proxy, ScriptEngine::ScriptOwnership, options);
695708 }