From 729bcac815689f690debbea7f07aa5d13974fad6 Mon Sep 17 00:00:00 2001 From: Shagen Ogandzhanian Date: Tue, 11 Jan 2022 18:10:13 +0100 Subject: [PATCH] Dispose skiko when it not used anymore --- examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt | 2 -- .../jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt b/examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt index 0cf36a01a1..4343f4c9c8 100644 --- a/examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt +++ b/examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt @@ -377,8 +377,6 @@ fun SomeCanvas() { ) } - Text(text = "Xxx") - Canvas( modifier = Modifier .size(400.dp) diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt index 67e21f7b73..412ebe12e1 100644 --- a/web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt @@ -14,9 +14,15 @@ import org.w3c.dom.HTMLCanvasElement @Composable fun ElementScope.skiko(block: @Composable () -> Unit) { DomSideEffect { canvas -> + var skikoCanvas: ComposeCanvas? = null + onWasmReady { - val skikoCanvas = ComposeCanvas(canvas) - skikoCanvas.setContent(block) + skikoCanvas = ComposeCanvas(canvas) + skikoCanvas?.setContent(block) + } + + onDispose { + skikoCanvas?.dispose() } } } \ No newline at end of file