Search code examples
androidout-of-memoryhorizontalscrollview

How to free images, which are not displayed on the screen, from HorizontalScrollView?


I'm working on an application which consists of many HorizontalScrollViews. Initially, everything was fine. But as the application is growing, and more images need to be loaded, I'm facing OutOfMemoryError. This is because I'm running out of native memory. Therefore, I want to release those views which are not visible on the screen, just like ViewPager. But, I do not want the snap effect. I want it to scroll freely. Thanks

UPDATE: I'm working on Gingerbread.


Solution

  • Consider using Horizontal List View, since it seems your list is actually growing and it is not the intended usage of ScrollViews. A ScrollView is suppose to have limited, and most probably static amount of child because it does not intended to dynamic release or create views.

    There's lots of tutorials about lazy loading and releasing list view's items. For instance, this is one.