Memory issue with volleyball cache

In my Android app, I use Volley to upload images to a custom listview.

when I update (delete all elements and load tiems) listview many times, my application is killed by this message

how can i fix this?

04-26 13: 08: 01.038: E / dalvikvm-heap (18040): Not enough memory allocated over 1684947261 bytes. 04-26 13: 08: 01.038: I / dalvikvm (18040): "Thread-11094" prio = 5 tid = 299 RUNNABLE 04-26 13: 08: 01.038: I / dalvikvm (18040): | group = "main" sCount = 0 dsCount = 0 obj = 0x439ea8e8 self = 0x7fb55250 04-26 13: 08: 01.038: I / dalvikvm (18040): | sysTid = 18946 nice = 10 sched = 0/0 cgrp = apps / bg_non_interactive handle = 2102160344 04-26 13: 08: 01.038: I / dalvikvm (18040): | state = R schedstat = (109248225 27367764 57) utm = 9 stm = 1 core = 2 04-26 13: 08: 01.038: I / dalvikvm (18040): in com.android.volley.toolbox.DiskBasedCache.streamToBytes (DiskBasedCache. java: ~ 316) 04-26 13: 08: 01.038: I / dalvikvm (18040): at com.android.volley.toolbox.DiskBasedCache.readString (DiskBasedCache.java∗26) 04-26 13: 08: 01.038: I / dalvikvm (18040): in com.android.volley.toolbox.DiskBasedCache.readStringStringMap (DiskBasedCache.java∗49) 04-26 13: 08: 01.038: I / dalvikvm (18040): at com.android.volley.toolbox. DiskBasedCache $ CacheHeader.readHeader (DiskBasedCache.javahaps92) 04-26 13: 08: 01.038: I / dalvikvm (18040): at com.android.volley.toolbox.DiskBasedCache.initialize (DiskBasedCache.java:155) 04-26 13: 08: 01.038: I / dalvikvm (18040): at com.android.volley.CacheDispatcher.run (CacheDispatcher.java:84) 04-26 13: 08: 01.048: W / dalvikvm (18040): threadid = 299: stream output with uncaught exception (group = 0x41745da0) 04-26 13: 08 : 01.048: I / SpenGestureManager (847): setFocusWindow0 04-26 13: 08: 01.048: D / PointerIcon (847): setHoveringSpenIconStyle1 pointerType: 10001iconType: 1 flag: 0 04-26 13: 08: 01.048: D / PointerIcon (8 ): setHoveringSpenCustomIcon IconType equally 1. 04-26 13: 08: 01.048: E / AndroidRuntime (18040): FATAL EXCEPTION: Thread-11094 04-26 13: 08: 01.048: E / AndroidRuntime (18040): Process: com.android.myapp, PID: 18040 04 -26 13: 08: 01.048: E / AndroidRuntime (18040): java.lang.OutOfMemoryError 04-26 13: 08: 01.048: E / AndroidRuntime (18040): in com.android.volley.toolbox.DiskBasedCache.streamToBytes (DiskBasedCache .java: 316) 04-26 13: 08: 01.048: E / AndroidRuntime (18040): at com.android.volley.toolbox.DiskBasedCache.readString (DiskBasedCache.java∗26) 04-26 13: 08: 01.048: E / AndroidRuntime (18040): on com.android.volley.toolbox.DiskBasedCache.readStringStringMap (DiskBasedCache.java►49) 04-26 13: 08: 01.048: E / AndroidRuntime (18040): at com.android.volley.toolbox. DiskBasedCache $ CacheHeader.readHeader (DiskBasedCache.javahaps92) 04-26 13: 08: 01.048: E / AndroidRuntime (18040): at com.android.volley.toolbox.DiskBasedCache.initialize (DiskBasedCache.java:155) 04-26 13: 08: 01.048: E / AndroidRuntime (18040): on com.android.volley.CacheDisp atcher.run (CacheDispatcher.java:84) 04-26 13: 08: 01.058: W / ActivityManager (847): force shutdown com.android.myapp / .feedlist.Feedlist

+7
android caching memory android-volley
source share
2 answers

You tried

RequestQueue volleyQueue = Volley.newRequestQueue(this); DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024); volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack())); volleyQueue.start(); 

of

stack overflow

This changes the cache size.

+1
source share

I had a very similar problem loading images in a ListView. It seems you have to take it out of the cache yourself.

Below is my implementation, which I have in my adapter public View getView(int position, View convertView, ViewGroup parent) :

 Bitmap cachedBitmap = imageCache.getBitmap(item.getPhotoUrl()); if (cachedBitmap != null) { holder.photo.setImageBitmap(cachedBitmap); } else { ImageLoader imageLoader = new ImageLoader(Volley.newRequestQueue(this.context), imageCache); imageLoader.get(item.getPhotoUrl(), new ImageLoader.ImageListener() { @Override public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) { if (item.getPhotoUrl() != null && response.getBitmap() != null) imageCache.putBitmap(item.getPhotoUrl(), response.getBitmap()); } @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); } }); //This is a custom imageview, you can create your own implementation for loading the image url to the imageview holder.photo.setImageUrl(item.getPhotoUrl(), imageLoader); } 
+1
source share

All Articles