Clear Patch for OpenMesh.. free all used memory on mesh clear

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@190 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2009-08-10 10:50:34 +00:00
parent 00613d349b
commit 4c8440de8f
5 changed files with 61 additions and 14 deletions

View File

@@ -64,7 +64,7 @@ public:
//-------------------------------------------------- constructor / destructor
PropertyContainer() {}
virtual ~PropertyContainer() { clear(); }
virtual ~PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
//------------------------------------------------------------- info / access
@@ -177,7 +177,16 @@ public:
void clear()
{
std::for_each(properties_.begin(), properties_.end(), Delete());
// Clear properties vector:
// Replaced the old version with new one
// which performs a swap to clear values and
// deallocate memory.
// Old version (changed 22.07.09) {
// std::for_each(properties_.begin(), properties_.end(), Delete());
// }
std::for_each(properties_.begin(), properties_.end(), ClearAll());
}
@@ -256,6 +265,12 @@ private:
size_t n_;
};
struct ClearAll
{
ClearAll() {}
void operator()(BaseProperty* _p) const { if (_p) _p->clear(); }
};
struct Swap
{
Swap(size_t _i0, size_t _i1) : i0_(_i0), i1_(_i1) {}