Updated the destructor for the C++ example to correctly release memory.
authorPadraig O'Sullivan <osullivan.padraig@gmail.com>
Sat, 19 Sep 2009 16:59:14 +0000 (12:59 -0400)
committerPadraig O'Sullivan <osullivan.padraig@gmail.com>
Sat, 19 Sep 2009 16:59:14 +0000 (12:59 -0400)
tests/cpp_example.cc

index 6feb26ab5e0b00baa3e7f25bfe8447dc0323e6fb..a9977ca7293aa09c11f3c192047979a789a9aeee 100644 (file)
@@ -5,6 +5,7 @@
 #include <vector>
 #include <string>
 #include <iostream>
+#include <algorithm>
 
 #include <string.h>
 
 using namespace std;
 using namespace memcache;
 
+class DeletePtrs
+{
+public:
+  template<typename T>
+  inline void operator()(const T *ptr) const
+  {
+    delete ptr;
+  }
+};
+
 class MyCache
 {
 public:
@@ -73,6 +84,7 @@ private:
 
   ~MyCache()
   {
+    for_each(clients.begin(), clients.end(), DeletePtrs());
     clients.clear();
   }