Stefan Oltmann
05/05/2025, 3:29 PMval imageBitmap = makeImageFromByteArray(bytes).toComposeImageBitmap()
The suggestion is to do this instead:
val image = makeImageFromByteArray(bytes)
val imageBitmap = image.use {
it.toComposeImageBitmap()
}
The reason behind that is that the SKIA image will not be closed after the copy process and the native resources not be freed up... That may be one of the issues for memory issues I experienced on iOS.
I don't find anything how to properly use toComposeImageBitmap()
Is is true that the SKIA image behind will not be freed immediately after a method like this completed?
fun createImage(bytes: ByteArray) = makeImageFromByteArray(bytes).toComposeImageBitmap()
Is there a way/need to dispose()/close() the ImageBitmap after the Composable disposes?ephemient
05/05/2025, 5:01 PMmakeImageFromByteArray
is, but if it returns a `org.jetbrains.skia.Image`:
• the native Skia image will be freed faster if you close
it
• it has a finalizer so it should be eventually freed after GCStefan Oltmann
05/05/2025, 6:26 PMtry {
return Image.makeFromEncoded(byteArray)
} catch (ex: IllegalArgumentException) {
throw ImageCreationException("Image.makeFromEncoded() failed.", ex)
}
Ok, so I can indeed improve memory usage if I close the Skia Image as fast as possible instead of waiting for the GC to do it eventually. The native resources will be released faster then.