Android - Out of memory Error. When it run on real device -
i have image gallery application, , i'm trying image external storage.my application can run on android emulator on real device(htc onex) got exception.
my log cat here.
07-25 17:17:49.027: e/dalvikvm-heap(3008): out of memory on 480016-byte allocation. 07-25 17:17:49.052: e/dalvikvm(3008): out of memory: heap size=65571kb, allocated=63717kb, limit=65536kb 07-25 17:17:49.052: e/dalvikvm(3008): info: footprint=65315kb, allowed footprint=65571kb, trimmed=0kb 07-25 17:17:49.052: e/mediastore(3008): failed allocate memory thumbnail content://media/external/images/thumbnails/300; java.lang.outofmemoryerror: (heap size=65571kb, allocated=63717kb) 07-25 17:17:49.142: e/dalvikvm-heap(3008): out of memory on 480016-byte allocation. 07-25 17:17:49.152: e/dalvikvm(3008): out of memory: heap size=65571kb, allocated=63718kb, limit=65536kb 07-25 17:17:49.152: e/dalvikvm(3008): info: footprint=65315kb, allowed footprint=65571kb, trimmed=0kb 07-25 17:17:49.152: e/mediastore(3008): failed allocate memory thumbnail content://media/external/images/thumbnails/300; java.lang.outofmemoryerror: (heap size=65571kb, allocated=63718kb) 07-25 17:17:49.302: e/dalvikvm-heap(3008): out of memory on 480016-byte allocation. 07-25 17:17:49.317: e/dalvikvm(3008): out of memory: heap size=65571kb, allocated=63749kb, limit=65536kb 07-25 17:17:49.317: e/dalvikvm(3008): info: footprint=65315kb, allowed footprint=65571kb, trimmed=0kb 07-25 17:17:49.327: e/androidruntime(3008): fatal exception: asynctask #1 07-25 17:17:49.327: e/androidruntime(3008): java.lang.runtimeexception: error occured while executing doinbackground() 07-25 17:17:49.327: e/androidruntime(3008): @ android.os.asynctask$3.done(asynctask.java:299) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.futuretask.run(futuretask.java:137) 07-25 17:17:49.327: e/androidruntime(3008): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 07-25 17:17:49.327: e/androidruntime(3008): @ java.lang.thread.run(thread.java:864) 07-25 17:17:49.327: e/androidruntime(3008): caused by: java.lang.outofmemoryerror: (heap size=65571kb, allocated=63749kb) 07-25 17:17:49.327: e/androidruntime(3008): @ android.graphics.bitmapfactory.nativedecodebytearray(native method) 07-25 17:17:49.327: e/androidruntime(3008): @ android.graphics.bitmapfactory.decodebytearray(bitmapfactory.java:552) 07-25 17:17:49.327: e/androidruntime(3008): @ android.media.thumbnailutils.createthumbnailfromexif(thumbnailutils.java:515) 07-25 17:17:49.327: e/androidruntime(3008): @ android.media.thumbnailutils.createimagethumbnail(thumbnailutils.java:102) 07-25 17:17:49.327: e/androidruntime(3008): @ android.provider.mediastore$internalthumbnails.getthumbnail(mediastore.java:626) 07-25 17:17:49.327: e/androidruntime(3008): @ android.provider.mediastore$images$thumbnails.getthumbnail(mediastore.java:987) 07-25 17:17:49.327: e/androidruntime(3008): @ com.mimi.ngsbusproject.galleryactivity.gallery(galleryactivity.java:92) 07-25 17:17:49.327: e/androidruntime(3008): @ com.mimi.ngsbusproject.galleryactivity.access$1(galleryactivity.java:74) 07-25 17:17:49.327: e/androidruntime(3008): @ com.mimi.ngsbusproject.galleryactivity$loadgallery.doinbackground(galleryactivity.java:58) 07-25 17:17:49.327: e/androidruntime(3008): @ com.mimi.ngsbusproject.galleryactivity$loadgallery.doinbackground(galleryactivity.java:1) 07-25 17:17:49.327: e/androidruntime(3008): @ android.os.asynctask$2.call(asynctask.java:287) 07-25 17:17:49.327: e/androidruntime(3008): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 07-25 17:17:49.327: e/androidruntime(3008): ... 5 more 07-25 17:17:50.062: e/windowmanager(3008): activity com.mimi.ngsbusproject.galleryactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview@41ac90a8 added here 07-25 17:17:50.062: e/windowmanager(3008): android.view.windowleaked: activity com.mimi.ngsbusproject.galleryactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview@41ac90a8 added here 07-25 17:17:50.062: e/windowmanager(3008): @ android.view.viewrootimpl.<init>(viewrootimpl.java:465) 07-25 17:17:50.062: e/windowmanager(3008): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:419) 07-25 17:17:50.062: e/windowmanager(3008): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:351) 07-25 17:17:50.062: e/windowmanager(3008): @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:171) 07-25 17:17:50.062: e/windowmanager(3008): @ android.view.window$localwindowmanager.addview(window.java:558) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.dialog.show(dialog.java:282) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.progressdialog.show(progressdialog.java:116) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.progressdialog.show(progressdialog.java:99) 07-25 17:17:50.062: e/windowmanager(3008): @ com.mimi.ngsbusproject.galleryactivity$loadgallery.onpreexecute(galleryactivity.java:51) 07-25 17:17:50.062: e/windowmanager(3008): @ android.os.asynctask.executeonexecutor(asynctask.java:586) 07-25 17:17:50.062: e/windowmanager(3008): @ android.os.asynctask.execute(asynctask.java:534) 07-25 17:17:50.062: e/windowmanager(3008): @ com.mimi.ngsbusproject.galleryactivity.oncreate(galleryactivity.java:43) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activity.performcreate(activity.java:5066) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1101) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activitythread.performlaunchactivity(activitythread.java:2307) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2387) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activitythread.access$600(activitythread.java:151) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activitythread$h.handlemessage(activitythread.java:1331) 07-25 17:17:50.062: e/windowmanager(3008): @ android.os.handler.dispatchmessage(handler.java:99) 07-25 17:17:50.062: e/windowmanager(3008): @ android.os.looper.loop(looper.java:155) 07-25 17:17:50.062: e/windowmanager(3008): @ android.app.activitythread.main(activitythread.java:5485) 07-25 17:17:50.062: e/windowmanager(3008): @ java.lang.reflect.method.invokenative(native method) 07-25 17:17:50.062: e/windowmanager(3008): @ java.lang.reflect.method.invoke(method.java:511) 07-25 17:17:50.062: e/windowmanager(3008): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1028) 07-25 17:17:50.062: e/windowmanager(3008): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:795) 07-25 17:17:50.062: e/windowmanager(3008): @ dalvik.system.nativestart.main(native method) 07-25 17:17:50.962: e/dalvikvm-heap(3008): out of memory on 2264368-byte allocation. 07-25 17:17:50.967: e/dalvikvm(3008): out of memory: heap size=65571kb, allocated=63787kb, limit=65536kb 07-25 17:17:50.967: e/dalvikvm(3008): info: footprint=65315kb, allowed footprint=65571kb, trimmed=0kb 07-25 17:17:50.967: e/androidruntime_2_crash(3008): crash in same process: main 07-25 17:17:50.967: e/androidruntime_2_crash(3008): java.lang.outofmemoryerror: (heap size=65571kb, allocated=63787kb) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ android.graphics.bitmapfactory.nativedecodeasset(native method) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:626) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:473) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ android.graphics.bitmapfactory.decoderesource(bitmapfactory.java:502) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ com.mimi.ngsbusproject.luancheractivity.decodesampledbitmapfromresource(luancheractivity.java:147) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ com.mimi.ngsbusproject.luancheractivity.animateandslideshow(luancheractivity.java:113) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ com.mimi.ngsbusproject.luancheractivity.access$0(luancheractivity.java:106) 07-25 17:17:50.967: e/androidruntime_2_crash(3008): @ com.mimi.ngsbusproject.luancheractivity$2.run(luancheractivity.java:84)
and code here.
final string[] columns = { mediastore.images.media.data, mediastore.images.media._id }; cursor image_cursor; image_cursor = managedquery( mediastore.images.media.external_content_uri, columns, null, null, null); int image_column_index = image_cursor .getcolumnindex(mediastore.images.media._id); count = image_cursor.getcount(); thumbnails = new bitmap[count]; arrpath = new string[count]; try { (int = 0; < count; i++) { image_cursor.movetoposition(i); int id = image_cursor.getint(image_column_index); int datacolumnindex = image_cursor .getcolumnindex(mediastore.images.media.data); thumbnails[i] = mediastore.images.thumbnails.getthumbnail( getapplicationcontext().getcontentresolver(), id, mediastore.images.thumbnails.mini_kind, null); arrpath[i] = image_cursor.getstring(datacolumnindex); } } catch (exception e) { e.printstacktrace(); }
sorry language. thanks.
your part:
count = image_cursor.getcount(); thumbnails = new bitmap[count];
may cause this. creating bitmaps memory-efficient should use bitmapoptions
try this instead:
bitmap bm; bm = bitmap.createscaledbitmap(bitmapfactory.decodefile(filepath),100, 100, true); mpicture = new imageview(context); mpicture.setimagebitmap(bm);
see strange out of memory issue while loading image bitmap object
seems these both logs may give hint:
failed allocate memory thumbnail content://media/external/images/thumbnails/300;
.
android.graphics.bitmapfactory.nativedecodebytearray(native method) 07-25 17:17:49.327: e/androidruntime(3008): @ android.graphics.bitmapfactory.decodebytearray(bitmapfactory.java:552) 07-25 17:17:49.327: e/androidruntime(3008): @ android.media.thumbnailutils.createthumbnailfromexif
does gallery contain lot of big pictures? in case dont have problem cursor
memory management when comes bitmaps!
furthermore should have permission in manifest:
<uses-permission android:name="android.permission.write_external_storage"/>
see also
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Comments
Post a Comment