Skip to content

Fix memory leak with LowEnergyBlock preconditioner when updating

Issue/feature addressed

The IncNavierStokesSolver with VelocityCorrectionScheme typically uses a LowEnergyBlock preconditioner for solving the Helmholtz problem for velocity. The preconditioner produces a memory leak when we update this velocity matrix in time, because the reference element created for the transformation matrix PreconR does not delete all matrices from the manager before the reference element itself is deleted. Another memory leak arises from not freeing the gs mappings similar to the PreconditionerBlock in ea2f8d00.

Proposed solution

Delete the local matrices for each reference element after the transformation matrix has been created. Also, use the Gs::free command to delete any gs mapping objects.


Adjustments are necessary insides PreconditionerLowEnergy::SetupReferenceElements(..) where we manually call HexExp->DropLocMatrices(HexR) with the MatrixKey HexR object. Additionally the matrices required to build this object need to be deleted. This is most conveniently done in Expansion3D::CreateMatrix(..).


  • We do not have a test setup with valgrind or any other memory checker.
  • I am adding a test that uses VCSImplicit + LowEnergyBlock preconditioner to have a reference case.

Suggested reviewers


Please add any other information that could be useful for reviewers.


  • Functions and classes, or changes to them, are documented.
  • User guide/documentation is updated.
  • Changelog is updated.
  • Suitable tests added for new functionality.
  • Contributed code is correctly formatted. (See the contributing guidelines).
  • License added to any new files.
  • No extraneous files have been added (e.g. compiler output or test data files).
Edited by Henrik Wustenberg

Merge request reports