Skip to content

Commit

Permalink
fix: close leaking okhttp response body (#196)
Browse files Browse the repository at this point in the history
* fix: close leaking okhttp response body

* fix: add cleaning context button to demo app
  • Loading branch information
nickybondarenko authored Feb 17, 2025
1 parent 56852a9 commit 5a14feb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ private fun Response.toResolveFlags(): ResolveResponse {
ignoreUnknownKeys = true
}
}
return ResolveResponse.Resolved(networkJson.decodeFromString(bodyString))
try {
return ResolveResponse.Resolved(networkJson.decodeFromString(bodyString))
} finally {
body.close()
}
} ?: throw ConfidenceError.ParseError("Response body is null", listOf())
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class MainActivity : ComponentActivity() {
Button(onClick = { vm.multiput() }) {
Text("MultiPut")
}
Button(onClick = { vm.clear() }) {
Text(text = "Clear out for re-fetching")
}
Surface(
modifier = Modifier
.padding(20.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ class MainVm(app: Application) : AndroidViewModel(app) {
refreshUi()
}
}

fun clear() {
Log.d(TAG, "clearing confidence")
for (key in confidence.getContext()) {
confidence.removeContext(key.key)
}
Log.d(TAG, "confidence context: ${confidence.getContext()}")
}
}

private fun <T> Evaluation<T>.toComposeColor(): Color {
Expand Down

0 comments on commit 5a14feb

Please sign in to comment.