diff options
author | Jian Liang <jianliang79@gmail.com> | 2015-12-25 21:36:46 +0800 |
---|---|---|
committer | jian liang <jianliang79@gmail.com> | 2016-01-22 14:07:19 +0000 |
commit | 3cc589c98390992e3ee8a7970dc2913ea857d623 (patch) | |
tree | 6c058e0bcd2c31661d370e7baed66d4cffaae32a /src/qml/memory | |
parent | 2d7921184e86c9dcd4189bd7da79b3fa050abedc (diff) |
Make sure we destroy all QV4::QObjectWrapper objects
Delay freeing QObjectWrapper Value to MemoryManager::sweep() to make sure
we can destroy all QObjectWrapper objects.
We also keep track of QObjectWrapper in QV4::Heap::ModelObject to make
sure we destory them in QV4::MemoryManager::sweep()
Change-Id: I3a8a3b07faab1f88c2eb746f68aa8d9584b40026
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/memory')
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 17 | ||||
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index 5181bf912b..885784d7d3 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -41,8 +41,6 @@ #include "StdLibExtras.h" #include <QTime> -#include <QVector> -#include <QVector> #include <QMap> #include <iostream> @@ -437,6 +435,21 @@ void MemoryManager::sweep(bool lastSweep) (*it) = Primitive::undefinedValue(); } + // Now it is time to free QV4::QObjectWrapper Value, we must check the Value's tag to make sure its object has been destroyed + const int pendingCount = m_pendingFreedObjectWrapperValue.count(); + if (pendingCount) { + QVector<Value *> remainingWeakQObjectWrappers; + remainingWeakQObjectWrappers.reserve(pendingCount); + for (int i = 0; i < pendingCount; ++i) { + Value *v = m_pendingFreedObjectWrapperValue.at(i); + if (v->tag() == Value::Undefined_Type) + PersistentValueStorage::free(v); + else + remainingWeakQObjectWrappers.append(v); + } + m_pendingFreedObjectWrapperValue = remainingWeakQObjectWrappers; + } + if (MultiplyWrappedQObjectMap *multiplyWrappedQObjects = engine->m_multiplyWrappedQObjects) { for (MultiplyWrappedQObjectMap::Iterator it = multiplyWrappedQObjects->begin(); it != multiplyWrappedQObjects->end();) { if (!it.value().isNullOrUndefined()) diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 3543da0907..e19cf301ea 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -49,6 +49,7 @@ #include <private/qv4value_p.h> #include <private/qv4scopedvalue_p.h> #include <private/qv4object_p.h> +#include <QVector> //#define DETAILED_MM_STATS @@ -327,6 +328,7 @@ public: QScopedPointer<Data> m_d; PersistentValueStorage *m_persistentValues; PersistentValueStorage *m_weakValues; + QVector<Value *> m_pendingFreedObjectWrapperValue; }; } |