Can anyone think of a reason why this would cause ...
# compose
a
Can anyone think of a reason why this would cause the App to run out of memory? If so, any ideas how to fix it?
Copy code
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
    AndroidView(factory = {
        val zoomableImageView = ZoomageView(it).apply {
            setImageBitmap(BitmapFactory.decodeFile(images?.get(page)?.path))
            restrictBounds = true
        }
        zoomableImageView
    }, modifier = Modifier.fillMaxSize())
}
A bit background info: This is basically an Image Preview Screen which displays the selected image and allows the user to navigate through images via swipe. I’m using an AndroidView to display the images, since there seems to be no proper implementation of a zoomable and draggable image in compose. The out of memory error occurs when scrolling through pages long enough. Possibly a bug in compose/horizontal pager?
c
What size are the bitmaps you're loading? You're likely loading 3 pages, so I'd guess that the bitmaps are too large. Take a look at Coil to load the images instead: https://coil-kt.github.io/coil/compose/
a
Thanks, will check and give an update very soon!
a
There is a Zoomable implementation!
👍 1
a
@Albert Chang Thank you! Will take a look!
m
i also had some problems with medium size drawables in a pager. For some reason, painter resources perform worst than accompanist drawablePainter. I have no idea why
a
@cb Ok, so I’ve tried loading the images into the ImageView using Picasso. Doesn’t really change anything, the memory still gets filled up everytime i scroll through the pager.
c
Pager isn't doing anything here other than laying out 3 items. I don't know how you're using Picasso, but you should be using
fit()
so that it downscales the images to fit the available size.
a
@Albert Chang Used your Zoomable implementation and it seems to work! Thank you so much 🙂
👍 1