I am downloading waveforms (images) and decoding them. These are very large in size. So my main problem is that, as I am installing the app, it is working perfectly. But after some time suddenly Logcat is giving the following errors. I think I had saved too many waveforms. So now I need to delete saved waveforms. So how can I delete the saved waveforms ?
02-21 17:06:30.146: I/dalvikvm-heap(13642): Clamp target GC heap from 259.610MB to 256.000MB
02-21 17:06:30.146: D/dalvikvm(13642): GC_FOR_ALLOC freed 453K, 2% free 257622K/262108K, paused 113ms, total 113ms
02-21 17:06:30.154: I/dalvikvm-heap(13642): Forcing collection of SoftReferences for 2016016-byte allocation
02-21 17:06:30.232: I/dalvikvm-heap(13642): Clamp target GC heap from 259.609MB to 256.000MB
02-21 17:06:30.232: D/dalvikvm(13642): GC_BEFORE_OOM freed 1K, 2% free 257620K/262108K, paused 85ms, total 85ms
02-21 17:06:30.240: E/dalvikvm-heap(13642): Out of memory on a 2016016-byte allocation.
02-21 17:06:30.240: I/dalvikvm(13642): "AsyncTask #5" prio=5 tid=18 RUNNABLE
02-21 17:06:30.240: I/dalvikvm(13642): | group="main" sCount=0 dsCount=0 obj=0x41e3a290 self=0x40067e08
02-21 17:06:30.240: I/dalvikvm(13642): | sysTid=13699 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1492300400
02-21 17:06:30.240: I/dalvikvm(13642): | state=R schedstat=( 0 0 0 ) utm=3297 stm=228 core=1
02-21 17:06:30.240: I/dalvikvm(13642): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
02-21 17:06:30.240: I/dalvikvm(13642): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
02-21 17:06:30.240: I/dalvikvm(13642): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:601)
02-21 17:06:30.240: I/dalvikvm(13642): at com.blackcobrastudios.footballchants.manager.SoundCloudManager.readBitmapFromResponse(SoundCloudManager.java:493)
02-21 17:06:30.240: I/dalvikvm(13642): at com.blackcobrastudios.footballchants.manager.SoundCloudManager$TaskCaller.doInBackground(SoundCloudManager.java:323)
02-21 17:06:30.240: I/dalvikvm(13642): at com.blackcobrastudios.footballchants.manager.SoundCloudManager$TaskCaller.doInBackground(SoundCloudManager.java:1)
02-21 17:06:30.240: I/dalvikvm(13642): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-21 17:06:30.240: I/dalvikvm(13642): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-21 17:06:30.240: I/dalvikvm(13642): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-21 17:06:30.240: I/dalvikvm(13642): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-21 17:06:30.240: I/dalvikvm(13642): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-21 17:06:30.240: I/dalvikvm(13642): at java.lang.Thread.run(Thread.java:856)
02-21 17:06:30.240: D/skia(13642): --- decoder->decode returned false
I do not understand that what is happening, and as I am getting these errors, my waveforms are not downloading.
public Bitmap readBitmapFromResponse(HttpResponse response)
throws IOException, OutOfMemoryError {
HttpEntity entity = response.getEntity();
BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
InputStream inputStream = b_entity.getContent();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, options);
options.inSampleSize = calculateInSampleSize(options, 1024, 16);
Log.d("WAVE_SIZE", "Sample size = " + options.inSampleSize);
options.inJustDecodeBounds = false;
inputStream.reset();
return BitmapFactory.decodeStream(inputStream);
}
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}