Examine your code. Check if you keep references to your bitmaps
somewhere (e.g. caches). Clean up these references and call
bitmap.recycle() on the bitmaps that you can let go. After a clean-up,
call System.gc(). This should not be necessary, but i found it does
actually help a little.

Use as few images as possible (e.g. if you have a list-view with items
containing images, be sure to reuse the 'contentView' parameter in the
getView() method of your adapter, if you have one defined).


On Aug 28, 1:51 am, Ramesh <[email protected]> wrote:
> Even after trying these methods i am getting the same error. The issue
> is in my application i am trying to load lots of images and when i
> navigate from one view to other, it still increases the memory. i.e.
> it's not freeing up / optimizing the memory which is now unused.
>
> Any idea how to deal with this ?
>
> On Jul 1, 6:58 pm, Streets Of Boston <[email protected]> wrote:
>
>
>
> > 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, 楊健 <[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-Hidequoted 
> > > text -
>
> > > - Show quoted text -- 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to