Unverified Commit 66616acc authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed memory leak (#4461)

parent 6c6bc628
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* https://github.com/Gallicchio-Lab/openmm-atmmetaforce-plugin * * https://github.com/Gallicchio-Lab/openmm-atmmetaforce-plugin *
* with support from the National Science Foundation CAREER 1750511 * * with support from the National Science Foundation CAREER 1750511 *
* * * *
* Portions copyright (c) 2021-2023 by the Authors * * Portions copyright (c) 2021-2024 by the Authors *
* Authors: Emilio Gallicchio * * Authors: Emilio Gallicchio *
* Contributors: Peter Eastman * * Contributors: Peter Eastman *
* * * *
...@@ -56,7 +56,8 @@ ...@@ -56,7 +56,8 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
ATMForceImpl::ATMForceImpl(const ATMForce& owner) : owner(owner), innerIntegrator0(1.0), innerIntegrator1(1.0) { ATMForceImpl::ATMForceImpl(const ATMForce& owner) : owner(owner), innerIntegrator0(1.0), innerIntegrator1(1.0),
innerContext0(NULL), innerContext1(NULL) {
Lepton::ParsedExpression expr = Lepton::Parser::parse(owner.getEnergyFunction()).optimize(); Lepton::ParsedExpression expr = Lepton::Parser::parse(owner.getEnergyFunction()).optimize();
energyExpression = expr.createCompiledExpression(); energyExpression = expr.createCompiledExpression();
u0DerivExpression = expr.differentiate("u0").createCompiledExpression(); u0DerivExpression = expr.differentiate("u0").createCompiledExpression();
...@@ -81,6 +82,10 @@ ATMForceImpl::ATMForceImpl(const ATMForce& owner) : owner(owner), innerIntegrato ...@@ -81,6 +82,10 @@ ATMForceImpl::ATMForceImpl(const ATMForce& owner) : owner(owner), innerIntegrato
} }
ATMForceImpl::~ATMForceImpl() { ATMForceImpl::~ATMForceImpl() {
if (innerContext0 != NULL)
delete innerContext0;
if (innerContext1 != NULL)
delete innerContext1;
} }
void ATMForceImpl::copySystem(ContextImpl& context, const OpenMM::System& system, OpenMM::System& innerSystem) { void ATMForceImpl::copySystem(ContextImpl& context, const OpenMM::System& system, OpenMM::System& innerSystem) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment