Load the picture in the size you need it, by setting the
BitmapFactory.Options.inSampleSize to a value larger than 1 (so far, i
have only managed to use value that are powers of 2 for this
inSampleSize attribute). Look at the api-docs for more info on this
attribute.

What i mean is that if you load the picture to be shown on your
screen, you need only a 320x480 pic, i.e. a inSampleSize=4 would do.

If you load your pic as a small thumbnail, even a larger value of
inSampleSize would do.

Also, if you load a pic to be shown on the screen, use RGB_565 and not
ARGB_8888. RGB_565 uses only 2 bytes per pixel, ARGB_8888 uses 4 bytes
per pixel.

In my app, i have managed to load on full-sized RGB_565 (2048x1536)
and a bunch of smaller pics at the same time. Or a 2 half-sized
ARGB_8888 (1024x768) and a bunch of smaller sized pics at the same
time.
Two full-sized RGB_565 always got me that out-of-memory exception.

I also wrote a 'bitmap-memory' notifier: Each class that created
bitmaps listens to this notifier. If notified, these classes will
recycle bitmaps and empty bitmap-caches (where possible). If another
class needs to create a large bitmap it will signal this 'bitmap-
notifier' to ask its listeners to clean up as much memory as possible.
This has worked for me so far.

On Jun 30, 11:00 pm, 楊健 <y...@cycomtech.co.jp> 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: android-developers@googlegroups.com
> [mailto:android-develop...@googlegroups.com] On Behalf Of Mark Murphy
> Sent: Wednesday, July 01, 2009 11:38 AM
> To: android-developers@googlegroups.com
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to