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/jsruntime/qv4persistent.cpp | |
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/jsruntime/qv4persistent.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4persistent.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index 4a0f84b685..1b0d6383e0 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -34,6 +34,7 @@ #include "qv4persistent_p.h" #include <private/qv4mm_p.h> #include "qv4object_p.h" +#include "qv4qobjectwrapper_p.h" #include "PageAllocation.h" using namespace QV4; @@ -381,7 +382,7 @@ WeakValue &WeakValue::operator=(const WeakValue &other) WeakValue::~WeakValue() { - PersistentValueStorage::free(val); + free(); } void WeakValue::set(ExecutionEngine *engine, const Value &value) @@ -412,3 +413,21 @@ void WeakValue::markOnce(ExecutionEngine *e) val->mark(e); } +void WeakValue::free() +{ + if (!val) + return; + + ExecutionEngine *e = engine(); + if (e && val->as<QObjectWrapper>()) { + // Some QV4::QObjectWrapper Value will be freed in WeakValue::~WeakValue() before MemoryManager::sweep() is being called, + // in this case we will never have a chance to call detroyObject() on those QV4::QObjectWrapper objects. + // Here we don't free these Value immediately, instead we keep track of them to free them later in MemoryManager::sweep() + e->memoryManager->m_pendingFreedObjectWrapperValue.push_back(val); + } else { + PersistentValueStorage::free(val); + } + + val = 0; +} + |