nss
nss

Reputation: 121

Android clean Virtual Memory

My application loads alot of data from a webservice. The problem is, after alot of network requests, it crashes from out of memory.

I'm using the volley library for the network requests, the Universal ImageLoader library for the loading and caching of images.

How do I prevent it from crashing? Is it possible to clean the virtual memory?

Upvotes: 2

Views: 435

Answers (2)

maxxxo
maxxxo

Reputation: 754

you can delete volley cache with clear() or set its size manualy Android Volley + JSONObjectRequest Caching

same with Universal ImageLoader library see https://github.com/nostra13/Android-Universal-Image-Loader - configuration

Upvotes: 0

Oleg Gryb
Oleg Gryb

Reputation: 5259

You can't tell JVM (Dalvik in this case) to clean memory "right now", because garbage collector will start (according to JVM specification) when it thinks a good time to do so. What you can do though is this:

  1. Assign null to all variables that refer objects that you don't need any more.
  2. Pay special attention to static variables that refer to big Java objects.
  3. Call System.gc() explicitly from your code, although remember that that call doesn't mean that garbage collection will start immediately. Rather consider this as an advice to JVM to start garbage collection as soon as possible.

Upvotes: 1

Related Questions