aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-08-14 14:17:10 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-24 11:31:33 +0200
commita4573dd927991937751f1e56cc02f7946f4f182b (patch)
tree76b795ba8d09ec38e5803276320ad44ddd344269 /src/qml
parentf1422adb3e71fd9c32b65fa0b9d3f076ed0ccfbb (diff)
Immediatley delete QV8QObjectResource objects to reduce memory leaks
This reduces memory leaks when deleting the v8 engine. Otherwise, the memory would only be reclaimed during a full GC run, which might not happen at all. Change-Id: Iac34bad1f2280adc530d3b3d7a074c5d022005a4 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com> Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index 58a7520297..627e453a77 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -926,12 +926,16 @@ static void FastValueSetterReadOnly(v8::Local<v8::String> property, v8::Local<v8
void QV8QObjectWrapper::WeakQObjectReferenceCallback(v8::Persistent<v8::Value> handle, void *wrapper)
{
Q_ASSERT(handle->IsObject());
- QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(handle->ToObject());
+ v8::Handle<v8::Object> v8object = handle->ToObject();
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(v8object);
Q_ASSERT(resource);
static_cast<QV8QObjectWrapper*>(wrapper)->unregisterWeakQObjectReference(resource);
if (static_cast<QV8QObjectWrapper*>(wrapper)->deleteWeakQObject(resource, false)) {
- qPersistentDispose(handle); // dispose.
+ // dispose
+ v8object->SetExternalResource(0);
+ delete resource;
+ qPersistentDispose(handle);
} else {
handle.MakeWeak(0, WeakQObjectReferenceCallback); // revive.
}