problems with bitmaps

by petunio » Fri, 10 Apr 2009 04:57:42 GMT


Sponsored Links
 Hi everybody

I am having a problem with the BitmapFactory:

this is my function, that reads a stream, and returns a bitmap:

        static Bitmap getBitmap(InputStream is) throws IOException
        {
           Bitmap bmp=null;

          //do some stuff...

           bmp=BitmapFactory.decodeStream(is);

           return bmp;
        }

after calling it a few times, it crashes giving me the following
error:

ERROR/(1329): VM won't let us allocate 215488 bytes
ERROR/AndroidRuntime(1329): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget


I am counting the memory used so far, and it's only 395328 bytes, so I
am sure there must be something else...

any ideas?

Thanks


--~--~---------~--~----~------------~-------~--~----~



problems with bitmaps

by jj » Fri, 10 Apr 2009 04:58:43 GMT


 Hi everybody

I am having a problem with the BitmapFactory:

this is my function, that reads a stream, and returns a bitmap:

        static Bitmap getBitmap(InputStream is) throws IOException
        {
           Bitmap bmp=null;

          //do some stuff...

           bmp=BitmapFactory.decodeStream(is);

           return bmp;
        }

after calling it a few times, it crashes giving me the following
error:

ERROR/(1329): VM won't let us allocate 215488 bytes
ERROR/AndroidRuntime(1329): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget


I am counting the memory used so far, and it's only 395328 bytes, so I
am sure there must be something else...

any ideas?

Thanks


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


problems with bitmaps

by mark . kahrl » Fri, 10 Apr 2009 07:37:02 GMT


 There's been a number of threads on this issue, the BitmapFactory
tends to throw this out of memory errors when it really shouldn't,
looks like a bug or memory leak. I'm not sure if it's cataloged as an
official bug though. Using bitmap.recycle(), and reducing the sample
size will mitigate , but not eliminate the problem. Also try reducing
the memory footprint of your images if possible. Hopefully this will
be recognized as a bug and fixed in a future release, at least I hope
so, I've had similar problems myself, and so have a number of other
developers.

                                            M



--~--~---------~--~----~------------~-------~--~----~



problems with bitmaps

by Romain Guy » Fri, 10 Apr 2009 07:44:09 GMT


 BitmapFactory does not leak. It throws an OutOfMemoryException when
there's no more memory available. That's all.







-- 
Romain Guy
Android framework engineer
romain...@android.com

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

--~--~---------~--~----~------------~-------~--~----~



problems with bitmaps

by Mark Murphy » Fri, 10 Apr 2009 07:53:12 GMT


 


If you have a reproducible test case, head over to  http://b.android.com 
and make it official.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~



problems with bitmaps

by Win Myo Htet » Mon, 27 Apr 2009 09:46:11 GMT


 I also get the OOME ( 6291456-byte) with bitmap file of 350KB (if it is
35KB, it is fine) when I do the rotation on the third time. I use
Bitmap.createScaledBitmap so that the pic fit into the screen and I also try
do myPic.recycle() in onSaveInstanceState to release the memory but it is
not helping. I wonder if I need to do myPic.compress instead of
Bitmap.createScaledBitmap and if I am not doing the proper myPic.recycle().






--~--~---------~--~----~------------~-------~--~----~



problems with bitmaps

by Jon Webb » Wed, 29 Apr 2009 01:38:32 GMT


 I didn't see an answer to your question. You should always recycle
your bitmaps when you're done with them.
     bmp.recycle();
That said, bitmaps do take up a lot of memory, and of course it has to
be contiguous, so you must be careful using them. E.g., use System.gc
() judiciously, etc.

-- Jon Webb




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Forward Locking A Specific Downloaded File

Is there a way to forward lock a specific film that my code downloads
to the android (like a wallpaper or ringtone)? I know you can forward
lock a package, but its resources still remain public, wondering if
its possible to just forward-lock a file.

Thanks much

(Apologies if this is a duplicate post, not sure if it made it through
the first time)

--~--~---------~--~----~------------~-------~--~----~

2. Which platform will our ADC2 apps run on?

It just occured to me today that while we targeted 1.5 as the platform
for your ADC2 apps, they may be running on 1.6.  That led me to wonder
about this situation:

What if there is a critical bug in the game/app that didn't exist in
1.5 but does on 1.6?  Is that fair to judge without being able to fix
the bug for the specific platform?
--~--~---------~--~----~------------~-------~--~----~

3. Directory playlist for music app

4. Automate performance testing

5. GPS Programming...

6. How to detect the availability of networks programatically in andriod emulator?

7. Installing the SDK alongside Amazon EC2 Tools on Mac