I know this is a common question but I did not find an appropriate answer to my problem in other threads.
I use bitmaps in my application for displaying profile pictures of users.
In addition, the app is like Instagram, so there is a page that is showing pictures from a database.
The problem is when I redirect between activities, i get often - "unfortunately application has stopped".
In the log I found the "out of memory" error.
I think it is because I should clean the memory by recycling bitmaps.
I don't know why its not working.
Please help me how to use bitmaps in way that would not make errors.
Here is part of the page where I print the bitmaps.
I have rows in database.
I use while and run all the rows.
I make new ImageViews, TextViews and I print them all like Instagram does.
Here you see how I print the picture every row:
ImageView v = new ImageView(this);
b2 = BitmapFactory.decodeByteArray(res4.getBlob(1), 0, res4.getBlob(1).length);
v.setImageBitmap(b2);
v.setId(count + 1);
p = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
p.width = width;
p.setMargins(0, 0, 0, 20);
p.addRule(RelativeLayout.BELOW, count);
rl.addView(v, p);
where should I recycle the bitmap? Is that the solution? here is a part of the log that shows "oom error":
10-05 18:53:31.184 16093-16093/com.example.user.instamath2 W/CursorWindow﹕ Window is full: requested allocation 1423987 bytes, free space 1241748 bytes, window size 2097152 bytes
10-05 18:53:31.201 16093-16093/com.example.user.instamath2 D/dalvikvm﹕ between the previous GC alloc 4461K
10-05 18:53:31.227 16093-16093/com.example.user.instamath2 I/dalvikvm-heap﹕ Clamp target GC heap from 132.368MB to 128.000MB
10-05 18:53:31.227 16093-16093/com.example.user.instamath2 D/dalvikvm﹕ GC_FOR_ALLOC freed 1229K (1749), 3% free 126908K/130816K, paused 25ms, total 25ms
10-05 18:53:31.227 16093-16093/com.example.user.instamath2 I/dalvikvm-heap﹕ Forcing collection of SoftReferences for 3149840-byte allocation
10-05 18:53:31.227 16093-16093/com.example.user.instamath2 D/dalvikvm﹕ between the previous GC alloc 0K
10-05 18:53:31.257 16093-16093/com.example.user.instamath2 I/dalvikvm-heap﹕ Clamp target GC heap from 132.360MB to 128.000MB
10-05 18:53:31.257 16093-16093/com.example.user.instamath2 D/dalvikvm﹕ GC_BEFORE_OOM freed 9K (44), 3% free 126899K/130816K, paused 31ms, total 31ms
10-05 18:53:31.257 16093-16093/com.example.user.instamath2 E/dalvikvm-heap﹕ Out of memory on a 3149840-byte allocation.
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ "main" prio=5 tid=1 RUNNABLE
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x41d00de0 self=0x41cee638
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ | sysTid=16093 nice=0 sched=0/0 cgrp=default handle=1074549128
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ | state=R schedstat=( 2032092377 14250700 588 ) utm=164 stm=39 core=2
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
10-05 18:53:31.258 16093-16093/com.example.user.instamath2 I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:529)