qdsfdhvh / compose-imageloader

Compose Image library for Kotlin Multiplatform.
https://qdsfdhvh.github.io/compose-imageloader/
MIT License
440 stars 15 forks source link

Memory Issue on iOS device while loading big pictures by batch #270

Open SongOnWater opened 1 year ago

SongOnWater commented 1 year ago

if change the default small image to raw image , as following "val imageUrl: String get() = urls?.raw ?: url " in Image.kt in the sample , the memory will be drained soon on iOS device.

qdsfdhvh commented 1 year ago

I tried to fix it by resizing the image and after testing the memory problem seems to be solved, but for some reason it crash easily, i need to work on it for a while.

SongOnWater commented 1 year ago

I tried to fix it by resizing the image and after testing the memory problem seems to be solved, but for some reason it crash easily, i need to work on it for a while.

Great, thanks for your effort. Hope you can make it well soon.

qdsfdhvh commented 1 year ago

@SongOnWater Hi, I found that there seems to be no top crash in kotlin 1.9.0, I am going to release a version based on kotlin 1.9.0, you can test it.

SongOnWater commented 1 year ago

That sounds like a good idea. But do you have any clue about the root cause of the issue.

qdsfdhvh commented 1 year ago

The error message is similar to this issue https://github.com/JetBrains/compose-multiplatform/issues/3138, I tried 1.9.0 only after reading this, but I'm not sure if it's a cause.

qdsfdhvh commented 1 year ago

I had published a version 1.6.5, you can try it.

SongOnWater commented 1 year ago

I have tried the version 1.6.5 and the latest code on master branch. It works better currently, not get crashed. But I have observed the memory usage on iOS device, it still keeps rising while you scroll the pictures to loading more or switch between the network, Gif or Svg scenes. As the memory increasing, the App will become sluggish. As comparison, I do the same test on Android device, the memory usage also rises after the operations, but it will fall down after a while. I think maybe the GC works on Android device to release the memory. The problem maybe that the GC not work or work well on iOS device with the code written by KMM.

qdsfdhvh commented 1 year ago

The current gc on native is not good, you can try new custom allocator by use freeCompilerArgs.add("-Xallocator=custom"). for more: https://kotlinlang.org/docs/whatsnew19.html#preview-of-custom-memory-allocator