File tree Expand file tree Collapse file tree
ksmt-z3/src/main/kotlin/org/ksmt/solver/z3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import com.microsoft.z3.decRefUnsafe
66import com.microsoft.z3.incRefUnsafe
77import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap
88import it.unimi.dsi.fastutil.longs.LongOpenHashSet
9+ import it.unimi.dsi.fastutil.longs.LongSet
910import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
1011import org.ksmt.KContext
1112import org.ksmt.decl.KDecl
@@ -259,24 +260,29 @@ class KZ3Context(
259260 return cached
260261 }
261262
262- /* *
263- * Note: we don't invoke decRef for each remaining expression/sort/...
264- * because native context releases all memory on close.
265- * */
266263 override fun close () {
267264 isClosed = true
268265
266+ z3Expressions.keys.decRefAll()
269267 expressions.clear()
270268 z3Expressions.clear()
271269
270+ tmpNativeObjects.decRefAll()
272271 tmpNativeObjects.clear()
273272
274- sorts.clear()
275- z3Sorts.clear()
276-
273+ z3Decls.keys.decRefAll()
277274 decls.clear()
278275 z3Decls.clear()
279276
277+ z3Sorts.keys.decRefAll()
278+ sorts.clear()
279+ z3Sorts.clear()
280+
280281 ctx.close()
281282 }
283+
284+ private fun LongSet.decRefAll () =
285+ longIterator().forEachRemaining {
286+ decRefUnsafe(nCtx, it)
287+ }
282288}
You can’t perform that action at this time.
0 commit comments