-//---------------------------- pointer.cc ---------------------------
+//---------------------------- pointer_02.cc ---------------------------
// $Id$
// Version: $Name$
//
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
-//---------------------------- pointer.cc ---------------------------
+//---------------------------- pointer_02.cc ---------------------------
// test what happens when serializing a pointer. is a new object created when
-// loading into another pointer that is NULL? this is in fact what happens
+// loading into another pointer that is non-NULL and the old pointer
+// destroyed? Or is the old object pointed to being co-opted? the former is in
+// fact what happens, and to make things just ever so slightly more awkward,
+// the previous object pointed to isn't freed but is left dangling, creating
+// the potential for a memory leak
#include "serialization.h"
#include <typeinfo>
int object_number = 1;
+int objects_destroyed = 0;
class C
{
<< std::endl;
}
+ ~C ()
+ {
+ deallog << "destructor. Object number "
+ << object_number
+ << std::endl;
+ ++objects_destroyed;
+ }
+
template <typename Archive>
void serialize (Archive &ar, const unsigned int version)
{
void test ()
{
- C *p1 = new C();
- C *p2;
+ {
+ C *p1 = new C();
+ C *p2 = new C();
- verify (p1, p2);
+ verify (p1, p2);
+
+ Assert (p1 != p2, ExcInternalError());
+
+ delete p1;
+ delete p2;
+ }
+
+ // as mentioned above, p2 is overwritten by
+ // a pointer to a new object, leaving the
+ // original object pointed to as a memory
+ // leak. assert that this behavior persists
+ Assert (objects_destroyed == 2, ExcInternalError());
}
int main ()
{
- std::ofstream logfile("pointer/output");
+ std::ofstream logfile("pointer_02/output");
deallog << std::setprecision(3);
deallog.attach(logfile);
deallog.depth_console(0);
--- /dev/null
+
+DEAL::Default constructor. Object number 1
+DEAL::Default constructor. Object number 2
+DEAL::Serializing object number 1 via N5boost7archive13text_oarchiveE
+DEAL::22 serialization::archive 9 0 1 0
+0
+
+DEAL::Default constructor. Object number 3
+DEAL::Serializing object number 3 via N5boost7archive13text_iarchiveE
+DEAL::destructor. Object number 1
+DEAL::destructor. Object number 3
+DEAL::OK