]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Make sure we don't run into a weird error with double deallocation of memory.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 17 Nov 2010 03:05:53 +0000 (03:05 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 17 Nov 2010 03:05:53 +0000 (03:05 +0000)
git-svn-id: https://svn.dealii.org/trunk@22782 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/examples/step-40/step-40.cc

index fbdcf5c0a3882d1c00419396deb012fcf1cbe241..e77a3e1fefa3271de6fa021ea73be6eca57c531d 100644 (file)
@@ -877,16 +877,34 @@ void LaplaceProblem<dim>::run ()
                                 // inialize and finalize PETSc, which
                                 // also initializes and finalizes the
                                 // MPI subsystem.
+                                //
+                                // Note how we enclose the use the
+                                // use of the LaplaceProblem class in
+                                // a pair of braces. This makes sure
+                                // that all member variables of the
+                                // object are destroyed by the time
+                                // we hit the
+                                // <code>PetscFinalize</code>
+                                // call. Not doing this will lead to
+                                // strange and hard to debug errors
+                                // when <code>PetscFinalize</code>
+                                // first deletes all PETSc vectors
+                                // that are still around, and the
+                                // destructor of the LaplaceProblem
+                                // class then tries to delete them
+                                // again.
 int main(int argc, char *argv[])
 {
   try
     {
       PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
       deallog.depth_console (0);
-
-      LaplaceProblem<2> laplace_problem_2d;
-      laplace_problem_2d.run ();
-
+      
+      {
+       LaplaceProblem<2> laplace_problem_2d;
+       laplace_problem_2d.run ();
+      }
+      
       PetscFinalize();
     }
   catch (std::exception &exc)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.