Browse Source

Added note of intentional lack of virtual destructor in HashBase and VectorBase. Closes #485.

Lasse Öörni 11 years ago
parent
commit
e5b379ec27

+ 3 - 6
Source/Engine/Container/HashBase.h

@@ -88,6 +88,9 @@ struct HashIteratorBase
 };
 
 /// Hash set/map base class.
+/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
+    and therefore %HashBase pointers should never be used.
+  */
 class URHO3D_API HashBase
 {
 public:
@@ -103,12 +106,6 @@ public:
     {
     }
 
-    /// Destruct.
-    ~HashBase()
-    {
-        delete[] ptrs_;
-    }
-    
     /// Swap with another hash set or map.
     void Swap(HashBase& rhs)
     {

+ 1 - 0
Source/Engine/Container/HashMap.h

@@ -189,6 +189,7 @@ public:
         Clear();
         FreeNode(Tail());
         AllocatorUninitialize(allocator_);
+        delete[] ptrs_;
     }
     
     /// Assign a hash map.

+ 1 - 0
Source/Engine/Container/HashSet.h

@@ -148,6 +148,7 @@ public:
         Clear();
         FreeNode(Tail());
         AllocatorUninitialize(allocator_);
+        delete[] ptrs_;
     }
     
     /// Assign a hash set.

+ 3 - 0
Source/Engine/Container/VectorBase.h

@@ -145,6 +145,9 @@ template <class T> struct RandomAccessConstIterator
 };
 
 /// %Vector base class.
+/** Note that to prevent extra memory use due to vtable pointer, %VectorBase intentionally does not declare a virtual destructor
+    and therefore %VectorBase pointers should never be used.
+  */
 class URHO3D_API VectorBase
 {
 public: