I'm still seeing this problem. I've used the bitmap.recycle() which
seems to mitigate this problem, but not get rid if it entirely. I'm
only processing one bitmap at a time, I recycle the bitmap, null it,
and call gc(). Runtime.freeMemory() indicates that I have over 10 MB
free memory, none of my bitmaps are over 3.5 MB, I only process one at
a time, yet this problem still occurs intermittently. Is this a bug or
low level memory leak? I've spent a considerable amount of time on
this issue, but cannot seem to resolve it. I'd at least like to know
if this is a documented bug, or if there is any hope of a resolution
in future Android version. The problem seems to arise from
BitmapFactory.decodeFile() . I've communicated with other developers
that seem to have almost the exact same problem. I'd like to at least
know if this is on the radar as a bug, and if there is any chance it
will be dealt with in a future version of Android. Thanks
Mark
On Jan 8, 3:29 pm, Romain Guy <[email protected]> wrote:
> Use less memory. One full screen PNG uses roughly 480*320*4 bytes (~=
> 614k.) Since you enable caching, you are doubling that amount to
> ~1.2MB per view. With 5 views you are using about 6 MB of memory (out
> of 16 MB maximum) just for the background images.
>
>
>
>
>
> On Thu, Jan 8, 2009 at 3:27 PM, Rohit <[email protected]> wrote:
>
> > I am setting the Background (using view.setBackgroundResource()) of
> > about 5 views with pngs that fill up the entire screen (as a
> > backdrop). I scroll between these 5 views and thus want to keep them
> > in cache (I use view.setChildrenCacheEnabled()) but I run into the
> > OutOfMemoryError: bitmap exceeds VM budget error. Is there a way to
> > overcome it?
>
> > Rohit
>
> > n Dec 17 2008, 11:20 am, Mark K <[email protected]> wrote:
> >> Thanks for the beta on the bitmap,recycle(), it works! Before
> >> processing the next bitmap I use this code to free up memory. I have a
> >> class level Bitmap object.
>
> >> Bitmap bm;// class level
>
> >> if (bm!=null)
> >> {
> >> bm.recycle();
> >> try
> >> {
> >> Thread.sleep(100);
> >> }
> >> catch(Exception e){}
> >> bm=null;
> >> System.gc();
> >> try
> >> {
> >> Thread.sleep(100);
> >> }
> >> catch(Exception e){}
> >> }
> >> // create new bitmap and start again.
>
> >> Thanks again, it works!
>
> >> On Dec 17, 5:56 am, Mike Reed <[email protected]> wrote:
>
> >> > Its a little raw, but if you know you're absolutely done using a given
> >> > bitmap object, you can call bitmap.recycle(). This immediately frees
> >> > up the memory associated with the bitmap, and marks it as "dead",
> >> > meaning it cannot be referenced again (i.e. don't try to draw or get/
> >> > set its pixels anymore).
>
> >> > i.e.
>
> >> > for (all of my big images) {
> >> > Bitmap b = decode(...);
> >> > canvas.drawBitmap(b, ...);
> >> > b.recycle();
> >> > // yikes, don't reference b again)
>
> >> > }
>
> >> > On Dec 15, 2008, at 9:04 PM, Mark K wrote:
>
> >> > Is there a work around for this problem? Something I need to do
> >> > differently perhaps? It seems like garbage collection is not occurring
> >> > between successive bitmap decoding operations. Explicitly calling gc()
> >> > does not seem to help. This is particularly a problem on the G1,
> >> > because there is no way to reduce the camera resolution, all of the
> >> > camera pictures are large. If I loop through a directory of pictures
> >> > taken by the camera and use BitmapFactory.decodeFile(), I will get an
> >> > out of memory error on the 2nd or 3rd iteration. Since I am only
> >> > displaying/decoding one bitmap at a time I would hope that garbage
> >> > collection would free up the memory between operations such that this
> >> > does not occur. Any help would be greatly appreciated. Here's the code
> >> > I use: This code runs a slide show of the images in the camera
> >> > directory, it uses Handler.postDelayed() to render each picture. Is
> >> > there anyway to tweak the code to get rid of the out of memory
> >> > problem.
>
> >> > public boolean slideShow()
> >> > {
> >> > String baseDir = "/sdcard/dcim/Camera/";
> >> > long showTime = 1500;
>
> >> > File dir = new File(baseDir);
> >> > File[] pics = dir.listFiles();
> >> > for ( int i=0; i<pics.length; i++ )
> >> > {
> >> > String pic=baseDir+pics[i].getName();
> >> > handler.postDelayed(new ShowSlide(pic), i*showTime);
> >> > }
> >> > return true;
> >> > }
>
> >> > class ShowSlide extends Thread
> >> > {
> >> > String pc="";
> >> > public ShowSlide(String pc)
> >> > {
> >> > this.pc=pc;
> >> > }
> >> > public void run()
> >> > {
> >> > System.out.println("Showing picture: "+pc.toString());
> >> > displayPicture(pc);
> >> > }
> >> > }
>
> >> > public boolean displayPicture(String filepath)
> >> > {
> >> > File file = new File(filepath);
> >> > BitmapFactory bfac = new BitmapFactory();
> >> > try
> >> > {
> >> > bm = bfac.decodeFile(filepath);// out of memory error
> >> > occurs
> >> > here!
> >> > handler.post(new SetImage(iView, bm));
> >> > }
> >> > catch(Exception e)
> >> > {
> >> > Log.e(TAG,"display picture failed: "+filepath+" "+e.toString
> >> > ());
> >> > e.printStackTrace();
> >> > return false;
> >> > }
>
> >> > return true;
> >> > }
>
> >> > class SetImage extends Thread
> >> > {
> >> > ImageView vv;
> >> > Bitmap bb;
> >> > public SetImage(ImageView vv, Bitmap bb)
> >> > {
> >> > this.vv=vv;
> >> > this.bb=bb;
> >> > }
> >> > public void run()
> >> > {
> >> > vv.setImageBitmap(bb);
> >> > }
> >> > }
>
> >> > On Dec 15, 2:48 pm, Romain Guy <[email protected]> wrote:
>
> >> > >> I've run into this exact same problem a number of times myself. Not
> >> > >> sure if its a bug or just a limitation of the jvm, can't seem to
> >> > >> process more than a few large bitmaps without this occuring, this
> >> > >> always seems to occur when decoding bitmaps from file.
>
> >> > > Neither, you are just using too much memory.
>
> >> > > --
> >> > > Romain Guy
> >> > > Android framework engineer
> >> > > [email protected]
>
> >> > > Note: please don't send private questions to me, as I don't have time
> >> > > to provide private support. All such questions should be posted on
> >> > > public forums, where I and others can see and answer them- Hide quoted
> >> > > text -
>
> >> > - Show quoted text -
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support. All such questions should be posted on
> public forums, where I and others can see and answer them- 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
-~----------~----~----~----~------~----~------~--~---