From db804640078a58a744430e65968f729d71e7b0e6 Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Thu, 22 Apr 2010 14:38:34 +0000 Subject: [PATCH] Avoid memory leaks: the inner solver is kept through a shared_ptr now [[Imported from SVN: r5927]] --- src/riemanniantrsolver.cc | 22 +++++++++++----------- src/riemanniantrsolver.hh | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/riemanniantrsolver.cc b/src/riemanniantrsolver.cc index 67ac4d3b..fd442219 100644 --- a/src/riemanniantrsolver.cc +++ b/src/riemanniantrsolver.cc @@ -103,16 +103,16 @@ setup(const GridType& grid, h1SemiNorm_ = new H1SemiNorm<CorrectionType>(*A); - innerSolver_ = new ::LoopSolver<CorrectionType>(mmgStep, - innerIterations_, - innerTolerance_, - h1SemiNorm_, - Solver::QUIET); + innerSolver_ = std::shared_ptr<LoopSolver<CorrectionType> >(new ::LoopSolver<CorrectionType>(mmgStep, + innerIterations_, + innerTolerance_, + h1SemiNorm_, + Solver::QUIET)); // Write all intermediate solutions, if requested if (instrumented_ - && dynamic_cast<IterativeSolver<CorrectionType>*>(innerSolver_)) - dynamic_cast<IterativeSolver<CorrectionType>*>(innerSolver_)->historyBuffer_ = "tmp/mgHistory"; + && dynamic_cast<IterativeSolver<CorrectionType>*>(innerSolver_.get())) + dynamic_cast<IterativeSolver<CorrectionType>*>(innerSolver_.get())->historyBuffer_ = "tmp/mgHistory"; // //////////////////////////////////////////////////////////// // Create Hessian matrix and its occupation structure @@ -234,8 +234,8 @@ void RiemannianTrustRegionSolver<GridType,TargetSpace>::solve() MonotoneMGStep<MatrixType,CorrectionType>* mgStep = NULL; // if the inner solver is a monotone multigrid set up a max-norm trust-region - if (dynamic_cast<LoopSolver<CorrectionType>*>(innerSolver_)) { - mgStep = dynamic_cast<MonotoneMGStep<MatrixType,CorrectionType>*>(dynamic_cast<LoopSolver<CorrectionType>*>(innerSolver_)->iterationStep_); + if (dynamic_cast<LoopSolver<CorrectionType>*>(innerSolver_.get())) { + mgStep = dynamic_cast<MonotoneMGStep<MatrixType,CorrectionType>*>(dynamic_cast<LoopSolver<CorrectionType>*>(innerSolver_.get())->iterationStep_); } @@ -330,8 +330,8 @@ void RiemannianTrustRegionSolver<GridType,TargetSpace>::solve() } else { // inner solver is a truncated cg - assert((dynamic_cast<TruncatedCGSolver<MatrixType,CorrectionType>*>(innerSolver_))); - dynamic_cast<TruncatedCGSolver<MatrixType,CorrectionType>*>(innerSolver_)->setProblem(*hessianMatrix_, + assert((dynamic_cast<TruncatedCGSolver<MatrixType,CorrectionType>*>(innerSolver_.get()))); + dynamic_cast<TruncatedCGSolver<MatrixType,CorrectionType>*>(innerSolver_.get())->setProblem(*hessianMatrix_, &corr, &backupRhs, trustRegion.radius()); diff --git a/src/riemanniantrsolver.hh b/src/riemanniantrsolver.hh index 7919ef3a..75e40dec 100644 --- a/src/riemanniantrsolver.hh +++ b/src/riemanniantrsolver.hh @@ -103,7 +103,7 @@ protected: const GeodesicFEAssembler<typename GridType::LeafGridView, TargetSpace>* assembler_; /** \brief The solver for the quadratic inner problems */ - Solver* innerSolver_; + std::shared_ptr<Solver> innerSolver_; /** \brief Dummy fields containing 'true' everywhere. The multigrid step expects them :-( */ -- GitLab