aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/memory
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-26 15:07:50 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-28 21:45:45 +0000
commit464b878b973710077b2b92b1682d6f38c83554dd (patch)
tree2577a70c9809bebc3776a0e11422badfdd310c90 /src/qml/memory
parentbead103138c0d9dff3c9f927c9c4e2f44ee7db4c (diff)
Implement support for WeakMap
Change-Id: Id23e80fe5918ba7dc897568123bf3db4d35e9092 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/memory')
-rw-r--r--src/qml/memory/qv4mm.cpp19
-rw-r--r--src/qml/memory/qv4mm_p.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index 258fac57af..065204b5d3 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -61,6 +61,7 @@
#include <algorithm>
#include "qv4alloca_p.h"
#include "qv4profiling_p.h"
+#include "qv4mapobject_p.h"
//#define MM_STATS
@@ -976,6 +977,18 @@ void MemoryManager::sweep(bool lastSweep, ClassDestroyStatsCallback classCountPt
(*it) = Primitive::undefinedValue();
}
+ // remove objects from weak maps and sets
+ Heap::MapObject *map = weakMaps;
+ Heap::MapObject **lastMap = &weakMaps;
+ while (map) {
+ if (map->isMarked()) {
+ map->removeUnmarkedKeys();
+ *lastMap = map;
+ lastMap = &map->nextWeakMap;
+ }
+ map = map->nextWeakMap;
+ }
+
// onDestruction handlers may have accessed other QObject wrappers and reset their value, so ensure
// that they are all set to undefined.
for (PersistentValueStorage::Iterator it = m_weakValues->begin(); it != m_weakValues->end(); ++it) {
@@ -1179,6 +1192,12 @@ size_t MemoryManager::getLargeItemsMem() const
return hugeItemAllocator.usedMem();
}
+void MemoryManager::registerWeakMap(Heap::MapObject *map)
+{
+ map->nextWeakMap = weakMaps;
+ weakMaps = map;
+}
+
MemoryManager::~MemoryManager()
{
delete m_persistentValues;
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index e3a011caf9..da162d2dfe 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -274,6 +274,8 @@ public:
return static_cast<typename ManagedType::Data *>(b);
}
+ void registerWeakMap(Heap::MapObject *map);
+
protected:
/// expects size to be aligned
Heap::Base *allocString(std::size_t unmanagedSize);
@@ -296,6 +298,7 @@ public:
PersistentValueStorage *m_persistentValues;
PersistentValueStorage *m_weakValues;
QVector<Value *> m_pendingFreedObjectWrapperValue;
+ Heap::MapObject *weakMaps = nullptr;
std::size_t unmanagedHeapSize = 0; // the amount of bytes of heap that is not managed by the memory manager, but which is held onto by managed items.
std::size_t unmanagedHeapSizeGCLimit;