I use `DisposableEffect` to cleanup some resources...
# compose-desktop
o
I use
DisposableEffect
to cleanup some resources hosted by a state object. When I close the window using the system close button, my
onDispose {}
isn't called (but `Window`'s
onDismissRequest {}
is). Is it expected? I feel it buggy, I would expect composable being disposed explicitly, no?
j
Yeah, probably we should call dispose when closing a window. Please go ahead and file a bug (https://github.com/JetBrains/compose-jb/issues)
👌 1
i
Yes, it is a bug. I suppose this only happens for Dialog's?
o
No, I have it with my main Window
I'll try to extract the smallest repro if that helps, in the meantime, I'll just raise the bug
I updated the issue with the smallest repro I managed to to
Copy code
fun main() {
    Window(
        size = IntSize(800, 600),
        onDismissRequest = {
            println("Window.onDismissRequest CALLED")
        }
    ) {
        var clickCount by remember { mutableStateOf(0) }
        if (clickCount < 5) {
            DisposableEffect(Unit) {
                onDispose {
                    println("DisposableEffect.onDispose CALLED")
                }
            }
            Text("Hello World! $clickCount", Modifier.clickable { ++clickCount })
        } else {
            Text("Clicked too much! $clickCount")
        }
    }
}
🙏 1