Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions ksmt-z3/src/main/kotlin/org/ksmt/solver/z3/KZ3Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.microsoft.z3.decRefUnsafe
import com.microsoft.z3.incRefUnsafe
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap
import it.unimi.dsi.fastutil.longs.LongOpenHashSet
import it.unimi.dsi.fastutil.longs.LongSet
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
import org.ksmt.KContext
import org.ksmt.decl.KDecl
Expand Down Expand Up @@ -259,24 +260,29 @@ class KZ3Context(
return cached
}

/**
* Note: we don't invoke decRef for each remaining expression/sort/...
* because native context releases all memory on close.
* */
override fun close() {
isClosed = true

z3Expressions.keys.decRefAll()
expressions.clear()
z3Expressions.clear()

tmpNativeObjects.decRefAll()
tmpNativeObjects.clear()

sorts.clear()
z3Sorts.clear()

z3Decls.keys.decRefAll()
decls.clear()
z3Decls.clear()

z3Sorts.keys.decRefAll()
sorts.clear()
z3Sorts.clear()

ctx.close()
}

private fun LongSet.decRefAll() =
longIterator().forEachRemaining {
decRefUnsafe(nCtx, it)
}
}