Search code examples
androidmemoryruntimeflickr

Free memory for android image loader


I am new to Android and i would like your advices on Volley Image loader. I have developed an application to load images using Volley Image loader. However, once I request to load more than 100 images, the performance and application will slow down and sometimes return OOM error. Would like to ask whether by running line of code below, am I able to free memory ? what is the best practises to free memory in an application ? How to manage memory using Volley image loader so that we can avoid OOM error?

Runtime.getRuntime().freeMemory()

Solution

  • Clearing memory manually is highly discouraged. The GC is supposed to do it and you should not interfere with it. In your volley implementation, you may use a caching (Memory and / or Disk)mechanism to improve your app's performance. Have a look at their sample repo here https://github.com/rdrobinson3/VolleyImageCacheExample where they are demonstrating the use of disk based caching for Volley.

    If I were you, I would use Picasso or Glide (recommended by Google) for loading network images in my app. These libraries handle caching internally so you don't have to worry about it.