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. OnItemClickListener cannot be resolved to a type

Hi,

I'm trying to run the example of ListView in this address:
http://developer.android.com/resources/tutorials/views/hello-listview.html

But I'm getting an error message for OnItemClickListener function:
"OnItemClickListener cannot be resolved to a type".

When I'm importing android.widget.AdapterView.OnItemClickListener
again I'm getting this error:
"The type new AdapterView.OnItemClickListener(){} must implement the
inherited abstract method
AdapterView.OnItemClickListener.onItemClick(AdapterView<?>, View, int,
long)"

This is the onCreate function:

@Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
COUNTRIES));

          ListView lv = getListView();
          lv.setTextFilterEnabled(true);

          lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
              // When clicked, show a toast with the TextView text
              Toast.makeText(getApplicationContext(), ((TextView)
view).getText(),
                  Toast.LENGTH_SHORT).show();
            }
          });
        }

How can I solve this error?

Thanks

--

2. Is it possible for my application to add items the the System Setup menu?

Currently I have a "setup" activity for I application.   Is it
possible to instead add something to the system Setup for my
application?

-Paul

--

3. Easy way to delete a bitmap?

4. ADB ERROR

5. Can I run pure Java jars on Android?

6. How to get reference of (SQLiteDatabase) to use android contact database

7. How to update kernel image (Kernel-qemu) on Emulator