diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 391e22a915..b4e3112768 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -70,6 +70,8 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) : NodeList::~NodeList() { delete _nodeTypesOfInterest; + clear(); + // stop the spawned threads, if they were started stopSilentNodeRemovalThread(); @@ -209,6 +211,19 @@ int NodeList::getNumAliveNodes() const { return numAliveNodes; } +void NodeList::clear() { + // delete all of the nodes in the list, set the pointers back to NULL and the number of nodes to 0 + for (int i = 0; i < _numNodes; i++) { + Node** nodeBucket = _nodeBuckets[i / NODES_PER_BUCKET]; + Node* node = nodeBucket[i % NODES_PER_BUCKET]; + + delete node; + node = NULL; + } + + _numNodes = 0; +} + void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) { delete _nodeTypesOfInterest; diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index da9c4a556a..57f8083113 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -65,6 +65,8 @@ public: int size() { return _numNodes; } int getNumAliveNodes() const; + void clear(); + void lock() { pthread_mutex_lock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); }