From 329a3462903c60876be3449c82d0bc16b72bf402 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 1 Apr 2013 11:07:18 -0700 Subject: [PATCH] Document percieved memory leak QJSEngine doesn't call collectGarbage upon deletion, because this operation can be expensive and in most cases the JS engine is deleted during application shutdown, when the memory can be deallocated cheaper. This can lead to an apparent memory leak if multiple engines are created and destroyed in the same process. Documenting how to avoid this. Change-Id: Ie02cb8bedc8821e0bb04dfa52a5a2d65b4b085a3 Reviewed-by: Christopher Adams --- src/qml/qml/qqmlengine.cpp | 2 ++ src/qml/qml/v8/qjsengine.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 5fa5cfd..1c3aff6 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -831,6 +831,8 @@ QQmlEngine::QQmlEngine(QQmlEnginePrivate &dd, QObject *parent) Any QQmlContext's created on this engine will be invalidated, but not destroyed (unless they are parented to the QQmlEngine object). + + See QJSEngine docs for details on cleaning up the JS engine. */ QQmlEngine::~QQmlEngine() { diff --git a/src/qml/qml/v8/qjsengine.cpp b/src/qml/qml/v8/qjsengine.cpp index 5b1464a..dbd0851 100644 --- a/src/qml/qml/v8/qjsengine.cpp +++ b/src/qml/qml/v8/qjsengine.cpp @@ -195,6 +195,10 @@ QJSEngine::QJSEngine(QJSEnginePrivate &dd, QObject *parent) /*! Destroys this QJSEngine. + + Garbage is not collected from the persistent JS heap during QJSEngine + destruction. If you need all memory freed, call collectGarbage manually + right before destroying the QJSEngine. */ QJSEngine::~QJSEngine() { -- 2.7.4