From fa38ad0b4909f39cfa481c23c05b7336fb65afcd Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 14 Dec 2012 13:02:44 +0000 Subject: [PATCH] 21948: EDF SMESH : Memory is not freed when deleting a mesh + void clear() --- src/SMDS/ObjectPool.hxx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/SMDS/ObjectPool.hxx b/src/SMDS/ObjectPool.hxx index 1ee371055..261ed6459 100644 --- a/src/SMDS/ObjectPool.hxx +++ b/src/SMDS/ObjectPool.hxx @@ -21,9 +21,18 @@ #define _OBJECTPOOL_HXX_ #include -#include +//#include #include +namespace +{ + // assure deallocation of memory of a vector + template void clearVector(std::vector& v ) + { + std::vector emptyVec; v.swap( emptyVec ); + } +} + template class ObjectPool { @@ -70,7 +79,7 @@ public: virtual ~ObjectPool() { - for (int i = 0; i < _chunkList.size(); i++) + for (size_t i = 0; i < _chunkList.size(); i++) delete[] _chunkList[i]; } @@ -101,7 +110,7 @@ public: void destroy(X* obj) { long adrobj = (long) (obj); - for (int i = 0; i < _chunkList.size(); i++) + for (size_t i = 0; i < _chunkList.size(); i++) { X* chunk = _chunkList[i]; long adrmin = (long) (chunk); @@ -121,6 +130,16 @@ public: } } + void clear() + { + _nextFree = 0; + _maxAvail = 0; + for (size_t i = 0; i < _chunkList.size(); i++) + delete[] _chunkList[i]; + clearVector( _chunkList ); + clearVector( _freeList ); + } + // void destroy(int toFree) // { // // no control 0<= toFree < _freeList.size() -- 2.39.2