From fba31a664e4a48640a59e469812f167b808b3f13 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 29 Nov 2001 15:07:08 +0000 Subject: [PATCH] Remove memory leak and generally improve infrastructure. git-svn-id: https://svn.dealii.org/trunk@5310 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/multigrid/mg_dof_handler.h | 51 +++++++---- .../source/multigrid/mg_dof_handler.cc | 84 +++++++++---------- 2 files changed, 74 insertions(+), 61 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/mg_dof_handler.h b/deal.II/deal.II/include/multigrid/mg_dof_handler.h index 56442cfb65..70a82b66f6 100644 --- a/deal.II/deal.II/include/multigrid/mg_dof_handler.h +++ b/deal.II/deal.II/include/multigrid/mg_dof_handler.h @@ -197,6 +197,13 @@ class MGDoFHandler : public DoFHandler virtual void distribute_dofs (const FiniteElement &, const unsigned int offset = 0); + /** + * Clear all data of this object + * and call the respective + * function of the base class. + */ + virtual void clear (); + /** * Actually do the renumbering based on * a list of new dof numbers for all the @@ -907,24 +914,27 @@ class MGDoFHandler : public DoFHandler }; -/** - * Distribute dofs on the given cell, - * with new dofs starting with index - * @p{next_free_dof}. Return the next - * unused index number. The finite - * element used is the one given to - * @p{distribute_dofs}, which is copied - * to @p{selected_fe}. - * - * This function is excluded from the - * @p{distribute_dofs} function since - * it can not be implemented dimension - * independent. - * - * Note that unlike for the usual dofs, - * here all cells and not only active - * ones are allowed. - */ + /** + * Distribute dofs on the given + * cell, with new dofs starting + * with index + * @p{next_free_dof}. Return the + * next unused index number. The + * finite element used is the one + * given to @p{distribute_dofs}, + * which is copied to + * @p{selected_fe}. + * + * This function is excluded from + * the @p{distribute_dofs} + * function since it can not be + * implemented dimension + * independent. + * + * Note that unlike for the usual + * dofs, here all cells and not + * only active ones are allowed. + */ unsigned int distribute_dofs_on_cell (cell_iterator &cell, unsigned int next_free_dof); @@ -934,6 +944,11 @@ class MGDoFHandler : public DoFHandler */ void reserve_space (); + /** + * Free all used memory. + */ + void clear_space (); + /** * Space to store the DoF numbers for the * different levels. Unlike the @p{levels} diff --git a/deal.II/deal.II/source/multigrid/mg_dof_handler.cc b/deal.II/deal.II/source/multigrid/mg_dof_handler.cc index d6fc4e1dc9..ac0b253e75 100644 --- a/deal.II/deal.II/source/multigrid/mg_dof_handler.cc +++ b/deal.II/deal.II/source/multigrid/mg_dof_handler.cc @@ -85,7 +85,10 @@ MGDoFHandler::MGDoFHandler (Triangulation &tria) : template -MGDoFHandler::~MGDoFHandler () {}; +MGDoFHandler::~MGDoFHandler () +{ + clear (); +}; #if deal_II_dimension == 1 @@ -1181,7 +1184,7 @@ void MGDoFHandler::distribute_dofs (const FiniteElement &fe, DoFHandler::distribute_dofs (fe, offset); -// reserve space for the MG dof numbers + // reserve space for the MG dof numbers reserve_space (); mg_used_dofs.resize (tria->n_levels(), 0); @@ -1369,6 +1372,19 @@ MGDoFHandler<3>::distribute_dofs_on_cell (cell_iterator &cell, #endif +template +void +MGDoFHandler::clear () +{ + // release own memory + clear_space (); + + // let base class release its mem + // as well + DoFHandler::clear (); +}; + + template unsigned int MGDoFHandler::n_dofs (const unsigned int level) const { Assert (level < mg_used_dofs.size(), ExcInvalidLevel(level)); @@ -1503,19 +1519,7 @@ void MGDoFHandler<1>::reserve_space () { ////////////////////////// // DESTRUCTION - - // delete all levels and set them up - // newly, since vectors are - // troublesome if you want to change - // their size - for (unsigned int i=0; i::reserve_space () { //////////////////////////// // DESTRUCTION - - // delete all levels and set them up - // newly, since vectors are - // troublesome if you want to change - // their size - for (unsigned int i=0; i::reserve_space () { //////////////////////////// // DESTRUCTION - - // delete all levels and set them up - // newly, since vectors are - // troublesome if you want to change - // their size - for (unsigned int i=0; i::reserve_space () { #endif +template +void MGDoFHandler::clear_space () +{ + // delete all levels and set them up + // newly, since vectors are + // troublesome if you want to change + // their size + for (unsigned int i=0; i tmp; + std::swap (mg_vertex_dofs, tmp); +}; + + + // explicit instantiations template class MGDoFHandler; + -- 2.39.5