I'm developing an android app that requires me to get some images from a server in order to display it in a scrollable pop-up once that pop-up is requested by the user, i'm trying to get all the images using universalImageLoader and storing them as a Bitmaps
but when getting the images and also after i got all of it, i got infinite displaying of GC_FOR_ALLOC
lines, and when pressing the button that displays the pop_up, the pop_up displayed normally but when begin to scroll down my app crashes and i got the following log messages:
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.758 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Build fingerprint: 'generic/vbox86tp/vbox86tp:4.3/JLS36G/eng.buildbot.20140128.092034:userdebug/test-keys'
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.758 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Revision: '0'
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.758 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): pid: 2269, tid: 2269, name: xample.solaceap >>> com.example.solaceap <<<
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.758 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 97808030
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.898 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): eax 00000000 ebx b757b6ff ecx 0000000a edx 9780803a
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:40.898 107: 107 I/DEBUG ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): esi 00000008 edi 00000001
.
.
.
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): channel '5284e038 com.example.solaceap/com.example.solaceap.Login (server)' ~ Consumer closed input channel or an error occurred. events=0x9
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:41.014 479: 518 E/InputDispatcher ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): channel '5284e038 com.example.solaceap/com.example.solaceap.Login (server)' ~ Channel is unrecoverably broken and will be disposed!
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 03-09 08:57:41.022 479: 518 W/InputDispatcher ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): channel '528b7508 PopupWindow:52a6ec40 (server)' ~ Channel is unrecoverably broken and will be disposed!
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Grow heap (frag case) to 6.773MB for 196620-byte allocation
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): GC_FOR_ALLOC freed 7K, 27% free 6864K/9292K, paused 14ms, total 14ms
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Attempted to unregister already unregistered input channel '5287e6f8 com.example.solaceap/com.example.solaceap.MainPage (server)'
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Process com.example.solaceap (pid 2269) has died.
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): WIN DEATH: Window{528afe84 u0 com.example.solaceap/com.example.solaceap.Media}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Attempted to unregister already unregistered input channel '528afe84 com.example.solaceap/com.example.solaceap.Media (server)'
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Force-removing child win Window{528b7508 u0 PopupWindow:52a6ec40} from container Window{528afe84 u0 com.example.solaceap/com.example.solaceap.Media}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Failed looking up window
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@5281f9fc does not exist
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7630)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7621)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1000)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at android.os.BinderProxy.sendDeathNotice(Binder.java:470)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.server.SystemServer.init1(Native Method)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.server.SystemServer.main(SystemServer.java:1066)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at java.lang.reflect.Method.invokeNative(Native Method)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at java.lang.reflect.Method.invoke(Method.java:525)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at dalvik.system.NativeStart.main(Native Method)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): WIN DEATH: null
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Late-enabling CheckJNI
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Start proc com.example.solaceap for activity com.example.solaceap/.MainPage: pid=2310 uid=10050 gids={50050, 3003, 1015, 1028}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): GC_FOR_ALLOC freed 39K, 4% free 2502K/2604K, paused 2ms, total 2ms
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Grow heap (frag case) to 5.000MB for 2621452-byte allocation
And this is how i get the images:
ImageLoader loader = ImageLoader.getInstance();
public static Map<Integer, Bitmap> movies_bitmaps = new HashMap<Integer, Bitmap>();
loader.loadImage(url, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
try {
int size = loadedImage.getWidth()
* loadedImage.getHeight();
ByteArrayOutputStream stream = new ByteArrayOutputStream(
size);
Bitmap modified_image = Bitmap.createScaledBitmap(loadedImage, 180, 230, false);
modified_image.compress(Bitmap.CompressFormat.JPEG, 100,
stream);
movies_bitmaps.put(index, modified_image);
loadedImage.recycle();
stream.close();
modified_image = null;
stream = null;
} catch (Exception e) {
e.printStackTrace();
}
Your code is going about doing nothing... first you create a ByteArrayOutputStream
with the size equal to image width*height, which is wrong no matter how you look at it: if you were writing raw bitmap data it should be 4*width*height, but you are writing a compressed JPG, whose resultant size would not correlate with image width/height. Then you close and set the stream to null so nothing is accomplished. Then you call loadedImage.recycle()
so loadedImage cannot ever be used again, but you put it in a Map with a clear intent to use it later...
Try removing loadedImage.recycle() and see if it helps, and read Android doc on Bitmap.recycle():
To answer some of your other questions in the comments:
so if that clearing the Bitmap, why the images were there then?
Per Android documenation:
This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references.
Basically it means if you called recycle()
, subsequent behavior is undefined as far API is concerned. If memory serves, the behavior is different pre-Andorid 4.0 and post(including) Android 4.0, since they've moved the byte[] buffer backing a Bitmap from native memory space into VM managed memory space.
GC_FOR_ALLOC messages still there.
Because you are still creating lots of large objects, it's normal. If you want to reduce it, remove the ByteArrayOutputStream
and associated code.