2

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?

nss
  • 121
  • 2
  • 11

2 Answers2

1

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.
Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • thanks, but my problem persists. I use only one Activity to multiple Fragments and I have ten different layouts, that is a problem? I clean all fragments after use them, but memory continues to increase. – nss May 29 '14 at 00:42
  • it would be very difficult to troubleshoot remotely. In traditional Java world there are tools like Wily Introscope. On Android - I simply don't know. I'll let you know if find anything. – Oleg Gryb May 29 '14 at 00:49
  • Actually, just by Googling I found this: http://www.slideshare.net/zblair/identifying-memory-leaks-in-android-applications Looks like a good starting point. – Oleg Gryb May 29 '14 at 00:51
  • thanks, I've identified the problem with your help. The problem is on volley requests, I have 92 instances of "com.android.volley.NetworkDispatcher", now I need to figure out why this is happening – nss May 29 '14 at 15:12
  • Yeah, I know, troubleshooting memory leaks is not fun especially if you're dealing with 3rd party libs. Good luck. – Oleg Gryb May 29 '14 at 15:52
  • I asked another question about it, I hope someone helps. This is the url: http://stackoverflow.com/questions/23937164/android-volley-networkdispatcher – nss May 29 '14 at 16:59
0

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

Community
  • 1
  • 1
maxxxo
  • 672
  • 3
  • 10
  • 28