I have an xml layout with 3 pages of ImageViews inside a custom view switcher. Not all of them are always visible.
I get an OOM exception on 2 of the devices I’ve tested on.
Is it possible to weak reference ImageViews accessed from findViewById?
My guess is that it isn’t, because there is already a hard reference to the ImageViews, and my first attempt didn’t solve the OOM issue. If it isn’t, is there another way to do this while keeping the ImageViews in the XML, I’d like to keep the UI and functionality separate.
Weak references don’t work on version 2.3+- they’ll compile, but they’ll always be collected as soon as there are no strong references. They wouldn’t help anyway if any view held a strong reference.
If the bitmaps can be paged in and out, the best idea is to recycle them as soon as they’re not displayed and reload them as needed.