Skip to content

Commit ed7f0f2

Browse files
committed
Allow driver to cleanup context if it owns the last shared pointer
1 parent 9d8d687 commit ed7f0f2

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/Variables.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Variables::Variables(SUNContext* ctx, const int flags) :
4646
_context(), _context_flags(flags) {
4747
if (_context == nullptr) {
4848
if (flags & CONTEXT_FLAG_GLOBAL) {
49-
std::cerr << "Using global context" << std::endl;
5049
init_global_sundials_context();
5150
_context = global_context;
5251
_context_flags |= CONTEXT_FLAG_GLOBAL;

src/drivers/driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ Driver::~Driver() {
164164
cmem = &CVodeMem::create();
165165
cmem->cvode_mem_free();
166166
cvode_mem = nullptr;
167+
if (_context.use_count() == 1)
168+
SUNContext_Free(_context.get());
169+
_context.reset();
167170
}
168171

169172
int Driver::calculate(realtype t, N_Vector u, N_Vector u_dot, void *user_data) {

tests/python/test_drivers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def wrapped_driver_vars(driver):
4848
x = Variables()
4949
x.readParam(fname_InputEvn)
5050
if driver == "EPS":
51-
# x.useC3 = True
5251
x.readParam(fname_InputATPCost)
5352
x.readEnzymeAct(fname_InputEnzyme)
5453
x.readGRN(fname_InputGRNC)

0 commit comments

Comments
 (0)