Android Question Simple question about recycle imageview

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
I tried a few things about recycling here in the forum but nothing very clear and explained.

what is the right way to use multiple images in a ImageView?

for example
i want to show a imageview where i will load around 50+ images with size 600x600 or more.

1 - the recycle its the correct function on this case?

What should I do to load all those images without memory crash or any other type of crash?

as I think it is
- Open app
- Show image on imageview
- Use recycle to clear the image
- show another image on imageview
- Use recycle to clear the image
- show another image on imageview
- Use recycle to clear the image
- show another image on imageview
.....

2 - this is correct to avoid crash?


3 - what the exacty time i need to use the recycle?
after loading an image in a ImageView
or when i want change the image of imageview for another image.


4 - this code its correct?
B4X:
Dim jo = imageview.bitmap As JavaObject
jo.RunMethod("recycle", Null)


i m working on app like a tinder, where i will load pictures every click, I need to avoid as much memory crash.

I really appreciate if someone can explain me.
thank you.

ps: i dont know if recycle its the right function to help me on this case.

thx
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
Just make sure that there are no live references to the bitmaps that are no longer used.
in my case i think i will use.

for example, i will make a app like Tinder or Hot or Not
i need use the recycle?
1 imageview will change the image every click.

the user can see around 50+ images on the same imageview.

its correct use the recycle on this case or have another way to avoid crash?
 
Upvote 0
Top