I would read an image slowly using a buffer if you want to avoid this. If you are trying to display the image use BitmapFactory.Options and increase the sample size to reduce the quality of the image but gain in memory.
Also, whenever you are done using a bitmap and you know it is not needed call recycle() on it. -dc On Jul 1, 6:00 am,ti 楊健 <[email protected]> wrote: > Thank you for you answer. > > I monitored the memory heap by Runtime.getRuntime().freeMemory() and > totalMemory();. > When my app starts (free is 700k,total is 2.7M) > When I take picture,the picture is 1.2M (free is 700k,total 5M) > The log shows 07-01 11:31:27.062: INFO/dalvikvm-heap(395): Grow heap (frag > case) to 5.020MB for 1337498-byte allocation > If I do not call System.gc() before i load the picture it will throw the OOM > exception as I pasted. > I thought at that time I just to allocate for 1.2M. > Is it means it is very dangerous to load picture ,I had better to check and > release the memory every time? > > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Mark Murphy > Sent: Wednesday, July 01, 2009 11:38 AM > To: [email protected] > Subject: [android-developers] Re: Is the limit of memory heap only 6M? > > 楊健 wrote: > > 07-01 11:32:02.192: VERBOSE/QualcommCameraHardware(35): state > > transition QCS_WAITING_JPEG --> QCS_IDLE > > 07-01 11:32:02.232: ERROR/dalvikvm-heap(395): 6291456-byte external > > allocation too large for this process. > > 07-01 11:32:02.232: ERROR/(395): VM won't let us allocate 6291456 > > bytes > > 07-01 11:32:02.242: DEBUG/AndroidRuntime(395): Shutting down VM > > 07-01 11:32:02.242: WARN/dalvikvm(395): threadid=3: thread exiting > > with uncaught exception (group=0x4000fe70) > > 07-01 11:32:02.242: ERROR/AndroidRuntime(395): Uncaught handler: > > thread main exiting due to uncaught exception > > 07-01 11:32:02.302: ERROR/AndroidRuntime(395): > > java.lang.OutOfMemoryError: bitmap size exceeds VM budget > > > My app shut down when i load a jpg file,i can avoid it by call > > system.gc().But I think memory limit will be 14M or 16M. > > The available heap is 16MB. That does not necessarily mean that there is > a contiguous 6MB buffer that you can allocate, depending on what else > your application is doing. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > Android App Developer Books:http://commonsware.com/books.html- Hide quoted > text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

