From 357dda3a7e68e317b0adae5b735fc83be99f43d7 Mon Sep 17 00:00:00 2001 From: Marc Pfetsch Date: Tue, 5 May 2026 18:42:30 +0200 Subject: [PATCH 1/3] release SOS constraints after addition The same is done after adding all other conss. --- src/pyscipopt/scip.pxi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index cc872aa1b..225da3156 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -7151,6 +7151,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddVarSOS1(self._scip, scip_cons, wrapper.ptr[i], weights[i])) PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) + PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons)) return self._getOrCreateCons(scip_cons) @@ -7216,6 +7217,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddVarSOS2(self._scip, scip_cons, wrapper.ptr[i], weights[i])) PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) + PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons)) return self._getOrCreateCons(scip_cons) From a1d1ba5747b474bfb7d2a61fa99890ac83023829 Mon Sep 17 00:00:00 2001 From: Marc Pfetsch Date: Tue, 5 May 2026 20:03:42 +0200 Subject: [PATCH 2/3] store python constraint and return it --- src/pyscipopt/scip.pxi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 225da3156..1d3427142 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -7151,9 +7151,10 @@ cdef class Model: PY_SCIP_CALL(SCIPaddVarSOS1(self._scip, scip_cons, wrapper.ptr[i], weights[i])) PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) + pyCons = self._getOrCreateCons(scip_cons) PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons)) - return self._getOrCreateCons(scip_cons) + return pyCons def addConsSOS2(self, vars, weights=None, name="", initial=True, separate=True, enforce=True, check=True, @@ -7217,9 +7218,10 @@ cdef class Model: PY_SCIP_CALL(SCIPaddVarSOS2(self._scip, scip_cons, wrapper.ptr[i], weights[i])) PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) + pyCons = self._getOrCreateCons(scip_cons) PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons)) - return self._getOrCreateCons(scip_cons) + return pyCons def addConsAnd(self, vars, resvar, name="", initial=True, separate=True, enforce=True, check=True, From 9e41c2c561e55e0807443d5a194d56b3342164c5 Mon Sep 17 00:00:00 2001 From: Marc Pfetsch Date: Wed, 6 May 2026 10:33:19 +0200 Subject: [PATCH 3/3] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d8fb8097..ada54121f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Added `getBase()` and `setBase()` methods to `LP` class for getting/setting basis status - Added `getMemUsed()`, `getMemTotal()`, and `getMemExternEstim()` methods - Added `isReoptEnabled()` and raising error if not enabled upon calling `reoptSolve()` +- SOS1/SOS2 constraints are now realease after addition similar to the other constraint types ### Fixed - Removed `Py_INCREF`/`Py_DECREF` on `Model` in `catchEvent`/`dropEvent` that caused memory leak for imbalanced usage - Used `getIndex()` instead of `ptr()` for sorting nonlinear expression terms to avoid nondeterministic behavior