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. DatabaseObjectNotClosedException When Using ContentProvider

Hello,

I am getting an
'android.database.sqlite.DatabaseObjectNotClosedException'.  I am
using a ContentProvider that I wrote following the standard method to
write such a provider which accesses a SQLite database.  I do not
'close' the cursor or database object in the ContentProvider.  Should
I be closing these objects inside of the ContentProvider for example
at the end of the query method?  Or should I be closing these objects
in the code that is using the ContentProvider?

Thanks,
Prasanna

-- 

2. Widget problems after application update.

Application has widget which basically shows the number of new message
count in the widget. Widget has title and Count.When application gets
updated, widget title gets replaced with message count, and some times
it shows problem loading widget. seems like R value not updated after
app update. However user removes the application or reboot the phone
widget icon shows properly. Is there any way to fix the issue?

Any suggestions.Here is the sample code

 public void onReceive(Context context, Intent intent) {

                String action = intent.getAction();

                if( AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) ) {
                    int layoutID = R.layout.WidgetLayout;
                    int[] ids =
intent.getIntArrayExtra( AppWidgetManager.EXTRA_APPWIDGET_IDS );

                    for (int i=0; i<ids.length; i++)
                    {
                       int appWidgetId = ids[i];

                       RemoteViews views = new 
RemoteViews(context.getPackageName(),
layoutID );
                       updateMessageCount(count);
                       AppWidgetManager manager =
AppWidgetManager.getInstance( context );
                       manager.updateAppWidget(appWidgetId, views);
                    }

               }
        }

-- 

3. InstantiationException when starting IntentService

4. Encrypt with Android using AES, decrypt with PHP...

5. filenotfoundexception on http get and post. just device. emu works

6. Instal hampir semua program ke SD card tanpa root (2.2)

7. FileNotFound Exception on Device not Emulator using URLConnection