Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
OutOfMemoryError BitmapFactory.nativeDecodeByte Array inside Threads
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 30 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
plusminus  
View profile  
 More options Dec 14 2008, 12:49 pm
From: plusminus <stoeps...@gmx.de>
Date: Sun, 14 Dec 2008 09:49:18 -0800 (PST)
Local: Sun, Dec 14 2008 12:49 pm
Subject: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
The following situation happens only in a few cases, but it does more
than once.
---------------------------------

I'm receiving several OutOfMemoryError in
BitmapFactory.nativeDecodeByteArray.

DDMS-Heap-View never broke the 16MB barrier. I can't even get it above
6MB, while going wild and smashing keys like a monkey:
-----------------------------------
1       5,820 MB        2,751 MB        3,069 MB        47,26%  54.433
-----------------------------------

The situation is that I have a ThreadPoolExector:
-----------------------------------
protected ExecutorService mThreadPool = Executors.newCachedThreadPool
();
-----------------------------------
... ,which load several 256x256 pngs to the RAM. (Average png-size: <
20kb)

StackTrace-Desciption:
That OutOfMemoryError happens several times in the Threads, until the
VM decides its enough and stops the whole process.

StackTrace:
#################################
W/AudioFlinger(   24): write blocked for 49 msecs
W/AudioFlinger(   24): write blocked for 48 msecs
W/AudioFlinger(   24): write blocked for 49 msecs
D/dalvikvm(  410): GC freed 31478 objects / 1613104 bytes in 196ms
D/dalvikvm(  410): GC freed 6404 objects / 991024 bytes in 151ms
D/dalvikvm(  410): GC freed 5224 objects / 1229888 bytes in 137ms
E/SOCKETLOG(  410): add_recv_stats recv 0
E/SOCKETLOG(  410): add_recv_stats recv 0
E/SOCKETLOG(  410): add_recv_stats recv 0
E/SOCKETLOG(  410): add_recv_stats recv 0
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
E/        (  410): VM won't let us allocate 65536 bytes
W/dalvikvm(  410): threadid=59: thread exiting with uncaught exception
(group=0x40010e28)
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-6
exiting due to uncaught exception
E/        (  410): VM won't let us allocate 65536 bytes
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
W/dalvikvm(  410): threadid=65: thread exiting with uncaught exception
(group=0x40010e28)
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
E/        (  410): VM won't let us allocate 65536 bytes
W/dalvikvm(  410): threadid=43: thread exiting with uncaught exception
(group=0x40010e28)
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-3
exiting due to uncaught exception
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
E/        (  410): VM won't let us allocate 65536 bytes
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-9
exiting due to uncaught exception
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
E/        (  410): VM won't let us allocate 65536 bytes
W/dalvikvm(  410): threadid=61: thread exiting with uncaught exception
(group=0x40010e28)
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
E/dalvikvm-heap(  410): 65536-byte external allocation too large for
this process.
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
E/        (  410): VM won't let us allocate 65536 bytes
I/Process (   50): Sending signal. PID: 410 SIG: 3
I/dalvikvm(  410): threadid=7: reacting to signal 3
I/dalvikvm(  410): Wrote stack trace to '/data/anr/traces.txt'
W/dalvikvm(  410): threadid=73: thread exiting with uncaught exception
(group=0x40010e28)
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-10
exiting due to uncaught exception
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
I/Process (   50): Sending signal. PID: 410 SIG: 3
W/ActivityManager(   50): Process org.andnav2 has crashed too many
times: killing!
D/ActivityManager(   50):   Force finishing activity
org.andnav2/.ui.map.OpenStreetDDMap
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-7
exiting due to uncaught exception
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
W/dalvikvm(  410): threadid=63: thread exiting with uncaught exception
(group=0x40010e28)
E/AndroidRuntime(  410): Uncaught handler: thread pool-8-thread-8
exiting due to uncaught exception
E/AndroidRuntime(  410): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime(  410):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime(  410):        at
org.andnav2.osm.views.tiles.OSMMapTileFilesystemCache$1.run
(OSMMapTileFilesystemCache.java:234)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
E/AndroidRuntime(  410):        at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
E/AndroidRuntime(  410):        at java.lang.Thread.run(Thread.java:
935)
D/ActivityManager(   50):   Force finishing activity
org.andnav2/.ui.sd.SDPOISearchList
D/ActivityManager(   50):   Force finishing activity
org.andnav2/.ui.sd.SDPOICategories
D/ActivityManager(   50):   Force finishing activity
org.andnav2/.ui.sd.SDMainChoose
D/ActivityManager(   50):   Force finishing activity
org.andnav2/.ui.Menu
I/dalvikvm(  410): threadid=7: reacting to signal 3
D/ActivityManager(   50): Force removing process ProcessRecord
{436057c0 410:org.andnav2/10023} (org.andnav2/10023)
I/Process (   50): Sending signal. PID: 410 SIG: 9
W/ActivityManager(   50): Some application object
android.os.BinderProxy@435a2848 tag AndroidRuntime has crashed, but I
don't know who it is.
W/ActivityManager(   50): ShortMsg:bitmap size exceeds VM budget
W/ActivityManager(   50): LongMsg:java.lang.OutOfMemoryError: bitmap
size exceeds VM budget
W/ActivityManager(   50): Some application object
android.os.BinderProxy@435a2848 tag AndroidRuntime ...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark K  
View profile  
 More options Dec 15 2008, 2:29 pm
From: Mark K <mark.ka...@gmail.com>
Date: Mon, 15 Dec 2008 11:29:18 -0800 (PST)
Local: Mon, Dec 15 2008 2:29 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

  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. Hopefully its
on the radar as a bug and will get fixed at some point. This is a
problem since de-coding bitmaps from file is a fairly common
operation.

                              Mark

On Dec 14, 9:49 am, plusminus <stoeps...@gmx.de> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Reed  
View profile  
 More options Dec 15 2008, 4:03 pm
From: Mike Reed <r...@google.com>
Date: Mon, 15 Dec 2008 16:03:19 -0500
Local: Mon, Dec 15 2008 4:03 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Depending on the details, bitmap pixels may be allocated in the VM  
heap or in the native heap, but in the latter case, we still debit the  
VM's heap by the amount that was allocated, so that in either case we  
don't exceed the per-app budget. This may explain why you're running  
out of heap even though DDMS doesn't see the allocations.

On Dec 15, 2008, at 2:29 PM, Mark K 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. Hopefully its
on the radar as a bug and will get fixed at some point. This is a
problem since de-coding bitmaps from file is a fairly common
operation.

                              Mark

On Dec 14, 9:49 am, plusminus <stoeps...@gmx.de> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Dec 15 2008, 5:48 pm
From: Romain Guy <romain...@google.com>
Date: Mon, 15 Dec 2008 23:48:35 +0100
Local: Mon, Dec 15 2008 5:48 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

>  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
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark K  
View profile  
 More options Dec 15 2008, 9:04 pm
From: Mark K <mark.ka...@gmail.com>
Date: Mon, 15 Dec 2008 18:04:10 -0800 (PST)
Local: Mon, Dec 15 2008 9:04 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

  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 <romain...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aditya marella  
View profile  
 More options Dec 16 2008, 1:34 pm
From: "aditya marella" <aditya.mare...@gmail.com>
Date: Wed, 17 Dec 2008 00:04:10 +0530
Local: Tues, Dec 16 2008 1:34 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

I too ran into this many times and my images are not on the disk they are
fetched from the network moreover none of my images exceed 5kb so i don't
understand why is it even trying to allocate 74752bytes.

11-26 15:40:34.967: ERROR/dalvikvm-heap(801): 74752-byte external allocation
too large for this process.
11-26 15:40:34.977: ERROR/(801): VM won't let us allocate 74752 bytes
11-26 15:40:35.277: DEBUG/AndroidRuntime(801): Shutting down VM
11-26 15:40:35.277: WARN/dalvikvm(801): threadid=3: thread exiting with
uncaught exception (group=0x40013e28)
11-26 15:40:35.287: ERROR/AndroidRuntime(801): Uncaught handler: thread main
exiting due to uncaught exception
11-26 15:40:35.537: ERROR/AndroidRuntime(801): java.lang.OutOfMemoryError:
bitmap size exceeds VM budget
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.graphics.Bitmap.nativeCreate(Native Method)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.graphics.Bitmap.createBitmap(Bitmap.java:343)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.View.buildDrawingCache(View.java:5219)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.View.getDrawingCache(View.java:5112)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1355)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.widget.AbsListView.dispatchDraw(AbsListView.java:1125)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.widget.ListView.dispatchDraw(ListView.java:2778)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.View.draw(View.java:5422)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1420)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1418)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.View.draw(View.java:5329)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.widget.FrameLayout.draw(FrameLayout.java:324)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1420)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1418)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.drawChild(ViewGroup.java:1418)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1192)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.View.draw(View.java:5329)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.widget.FrameLayout.draw(FrameLayout.java:324)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.jav a:1701)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewRoot.draw(ViewRoot.java:980)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewRoot.performTraversals(ViewRoot.java:829)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.os.Handler.dispatchMessage(Handler.java:88)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.os.Looper.loop(Looper.java:123)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
java.lang.reflect.Method.invokeNative(Native Method)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
java.lang.reflect.Method.invoke(Method.java:515)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 739)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
11-26 15:40:35.537: ERROR/AndroidRuntime(801):     at
dalvik.system.NativeStart.main(Native Method)
11-26 15:40:35.627: INFO/Process(55): Sending signal. PID: 801 SIG: 3
11-26 15:40:35.627: INFO/dalvikvm(801): threadid=7: reacting to signal 3
11-26 15:40:35.767: INFO/dalvikvm(801): Wrote stack trace to
'/data/anr/traces.txt'

-Aditya


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fadden  
View profile  
 More options Dec 16 2008, 8:42 pm
From: fadden <fad...@android.com>
Date: Tue, 16 Dec 2008 17:42:58 -0800 (PST)
Local: Tues, Dec 16 2008 8:42 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
On Dec 16, 10:34 am, "aditya marella" <aditya.mare...@gmail.com>
wrote:

> I too ran into this many times and my images are not on the disk they are
> fetched from the network moreover none of my images exceed 5kb so i don't
> understand why is it even trying to allocate 74752bytes.

What is the size of your image in pixels?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Reed  
View profile  
 More options Dec 17 2008, 8:56 am
From: Mike Reed <r...@google.com>
Date: Wed, 17 Dec 2008 08:56:59 -0500
Local: Wed, Dec 17 2008 8:56 am
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
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 <romain...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark K  
View profile  
 More options Dec 17 2008, 2:20 pm
From: Mark K <mark.ka...@gmail.com>
Date: Wed, 17 Dec 2008 11:20:59 -0800 (PST)
Local: Wed, Dec 17 2008 2:20 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
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 <r...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rohit  
View profile  
 More options Jan 8 2009, 6:27 pm
From: Rohit <mord...@gmail.com>
Date: Thu, 8 Jan 2009 15:27:14 -0800 (PST)
Local: Thurs, Jan 8 2009 6:27 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
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 <mark.ka...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Jan 8 2009, 6:29 pm
From: Romain Guy <romain...@google.com>
Date: Thu, 8 Jan 2009 15:29:56 -0800
Local: Thurs, Jan 8 2009 6:29 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
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.

--
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark K  
View profile  
 More options Jan 8 2009, 7:05 pm
From: Mark K <mark.ka...@gmail.com>
Date: Thu, 8 Jan 2009 16:05:43 -0800 (PST)
Local: Thurs, Jan 8 2009 7:05 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

  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 <romain...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nickthecook  
View profile  
 More options Jan 11 2009, 10:29 am
From: nickthecook <nickthec...@gmail.com>
Date: Sun, 11 Jan 2009 07:29:34 -0800 (PST)
Local: Sun, Jan 11 2009 10:29 am
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
I'm still seeing this problem as well. I can boot my phone, start my
app, load a single image (~300k) and have this error. I'm loading
images with the BitmapFactory.decodeByteArray() method, which calls
BitmapFactory.nativeDecodeByteArray().

What is interesting is that after I added a background thread to my
app to load and process images, I had a bug where changing the
orientation of the screen caused another thread to be started. As soon
as two of my threads were in BitmapFactory.nativeDecodeByteArray() at
the same time, this method would attempt to allocate over 6MB of
memory, and I would get the error.

E/dalvikvm-heap( 1204): 6291456-byte external allocation too large for
this process.
E/        ( 1204): VM won't let us allocate 6291456 bytes
D/skia    ( 1204): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed
W/dalvikvm( 1204): threadid=15: thread exiting with uncaught exception
(group=0x40013e28)
E/AndroidRuntime( 1204): Uncaught handler: thread Thread-12 exiting
due to uncaught exception
E/AndroidRuntime( 1204): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime( 1204):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime( 1204):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime( 1204):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime( 1204):        at
org.hopto.group18.postbot.Image.loadFileContents(Image.java:85)
E/AndroidRuntime( 1204):        at org.hopto.group18.postbot.EditPost$20.run
(EditPost.java:800)
E/AndroidRuntime( 1204):        at java.lang.Thread.run(Thread.java:935)

I'm using 500k buffers (down from 1MB, down from 1.5MB in an effort to
avoid OOMEs) to load images, the images themselves are ~300k (taken
with the phone's camera). I can't imagine why it is trying to allocate
6MB.

I have fixed my thread issue (even when not changing orientation this
issue occurs), and I am using locking to prevent two of my threads
from using this method at the same time, but I still see this error,
although less frequently.

It seems to come and go: sometimes I can't seem to load a single image
for a period of a minute or two, and then the problem will go away. Is
it possible that these errors can be the result of concurrent access
to this native method by my app and other apps?

On Jan 8, 7:05 pm, Mark K <mark.ka...@gmail.com> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nickthecook  
View profile  
 More options Jan 13 2009, 6:45 am
From: nickthecook <nickthec...@gmail.com>
Date: Tue, 13 Jan 2009 03:45:51 -0800 (PST)
Local: Tues, Jan 13 2009 6:45 am
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Does anyone know why this method would need to allocate 6MB? When this
issue occurs, it is always trying to allocate the same amount of
memory to the byte. It occurs with different images, of different
sizes. I load the file contents to a byte array and try to decode this
array into a Bitmap.

Here are two log excerpts in which the "LENGTH" message is showing the
length of the byte array from which I am trying to construct the
Bitmap:

D/Image   ( 5480): LENGTH: 363525
E/dalvikvm-heap( 5480): 6291456-byte external allocation too large for
this process.
E/        ( 5480): VM won't let us allocate 6291456 bytes
D/skia    ( 5480): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed
W/dalvikvm( 5480): threadid=15: thread exiting with uncaught exception
(group=0x40013e28)
E/AndroidRuntime( 5480): Uncaught handler: thread Thread-9 exiting due
to uncaught exception
E/AndroidRuntime( 5480): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime( 5480):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime( 5480):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime( 5480):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime( 5480):        at
org.hopto.group18.postbot.Image.loadFileContents(Image.java:88)
E/AndroidRuntime( 5480):        at org.hopto.group18.postbot.EditPost$20.run
(EditPost.java:806)
E/AndroidRuntime( 5480):        at java.lang.Thread.run(Thread.java:935)

...

D/Image   ( 5450): LENGTH: 391154
E/dalvikvm-heap( 5450): 6291456-byte external allocation too large for
this process.
E/        ( 5450): VM won't let us allocate 6291456 bytes
D/skia    ( 5450): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed
W/dalvikvm( 5450): threadid=15: thread exiting with uncaught exception
(group=0x40013e28)
E/AndroidRuntime( 5450): Uncaught handler: thread Thread-11 exiting
due to uncaught exception
E/AndroidRuntime( 5450): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget
E/AndroidRuntime( 5450):        at
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
E/AndroidRuntime( 5450):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:234)
E/AndroidRuntime( 5450):        at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:247)
E/AndroidRuntime( 5450):        at
org.hopto.group18.postbot.Image.loadFileContents(Image.java:88)
E/AndroidRuntime( 5450):        at org.hopto.group18.postbot.EditPost$20.run
(EditPost.java:806)
E/AndroidRuntime( 5450):        at java.lang.Thread.run(Thread.java:935)

I'm certainly open to the possibility that this is my fault, but if so
I'd like to know what I'm doing wrong, or if anyone is looking at the
native code involved for problems.

Thanks!

On Jan 11, 10:29 am, nickthecook <nickthec...@gmail.com> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
blindfold  
View profile  
 More options Jan 13 2009, 8:21 am
From: blindfold <seeingwithso...@gmail.com>
Date: Tue, 13 Jan 2009 05:21:29 -0800 (PST)
Local: Tues, Jan 13 2009 8:21 am
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Sounds like your have ~300 KB JPEG-compressed images at the standard
G1 resolution of 2048 * 1536. At 2 bytes per pixel (using RGB_565 or
ARGB_4444 format) this will in your phone expand into 2048 * 1536 * 2
= 6291456 bytes uncompressed. That's a sizable chunk of memory.

Regards

On Jan 11, 4:29 pm, nickthecook <nickthec...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nickthecook  
View profile  
 More options Jan 13 2009, 10:27 pm
From: nickthecook <nickthec...@gmail.com>
Date: Tue, 13 Jan 2009 19:27:41 -0800 (PST)
Local: Tues, Jan 13 2009 10:27 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Interesting!

I'm usually able to load these images without a problem. Maybe 1 in 5
loads fails. Since they are all the same size, I would expect all
calls to fail like this, or none, but that number is definitely not a
coincidence.

Anyway, I'm now using the version of decodeByteArray that takes
options with inSampleSize = 2, and can't get it to crash no matter how
many images I try to process in a row, so the problem is gone for now,
at least.

Thanks for the insight!

On Jan 13, 8:21 am, blindfold <seeingwithso...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rohit  
View profile  
 More options Jan 14 2009, 7:32 pm
From: Rohit <mord...@gmail.com>
Date: Wed, 14 Jan 2009 16:32:17 -0800 (PST)
Local: Wed, Jan 14 2009 7:32 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
If I want to set the background resource of a view with a large PNG,
what is the best way to do it? Right now I just call
setBackgroundResource with the id of the resource eg.
R.drawable.wallpaper_news. Is there a better way to do it using
decodeByteArray? I have a couple of views to set the background for.
Which method is it best to do it in? Is dispatchDraw a good place?

Rohit

On Jan 13, 7:27 pm, nickthecook <nickthec...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ad  
View profile  
 More options Jan 25 2009, 8:23 am
From: ad <avra...@gmail.com>
Date: Sun, 25 Jan 2009 05:23:23 -0800 (PST)
Local: Sun, Jan 25 2009 8:23 am
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
YES YES YES!!!
I've found solution for that bug.
It's tricky but it works.
Place that on the begining of your code.

                try{
                                Bitmap tmpBitmap = Bitmap.createBitmap
(3200, 4800,
Config.ARGB_8888);
                }catch(Throwable e){
                        e.printStackTrace();
                        System.out.println("CATCHED !!!!");

                }

I was fighting with that about 4 days.
Hope anyone is happy now, that was hell.

Regards,
avram.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
blindfold  
View profile  
 More options Jan 25 2009, 8:49 am
From: blindfold <seeingwithso...@gmail.com>
Date: Sun, 25 Jan 2009 05:49:57 -0800 (PST)
Local: Sun, Jan 25 2009 8:49 am
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
How can this possibly help you? You are trying to allocate 61 MB
(3200*4800*4 bytes), which lies well above the 16 MB heap limit. I
tried once to allocate, say, 12 MB at program startup to keep Android
from all the time bumping into the heap limit and possibly crashing as
a result in case its memory management is not 100% reliable, but
trying to allocate 61 MB should not offer any benefit?

Regards

On Jan 25, 2:23 pm, ad <avra...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ad  
View profile  
 More options Jan 25 2009, 2:30 pm
From: ad <avra...@gmail.com>
Date: Sun, 25 Jan 2009 11:30:18 -0800 (PST)
Local: Sun, Jan 25 2009 2:30 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Check first, and think a bit.

On Jan 25, 2:49 pm, blindfold <seeingwithso...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
blindfold  
View profile  
 More options Jan 26 2009, 6:09 pm
From: blindfold <seeingwithso...@gmail.com>
Date: Mon, 26 Jan 2009 15:09:24 -0800 (PST)
Local: Mon, Jan 26 2009 6:09 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads

> Check first, and think a bit.

I stand by what I said.

Regards

On Jan 25, 8:30 pm, ad <avra...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rohit  
View profile  
 More options Feb 4 2009, 2:05 pm
From: Rohit <mord...@gmail.com>
Date: Wed, 4 Feb 2009 11:05:36 -0800 (PST)
Local: Wed, Feb 4 2009 2:05 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
I noticed that the OutOfMemoryError occurs a lot when you try to load
an image that is larger than the view. Android needs to scale the
image down to fit the view and that is when it seems to crash out as a
result of the OutOfMemoryError.

Rohit

On Jan 26, 3:09 pm, blindfold <seeingwithso...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Feb 4 2009, 2:07 pm
From: Romain Guy <romain...@google.com>
Date: Wed, 4 Feb 2009 11:07:54 -0800
Local: Wed, Feb 4 2009 2:07 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Scaling the image down happens at drawing time. You are just using
images that are too large to begin with.

--
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rohit  
View profile  
 More options Feb 4 2009, 2:11 pm
From: Rohit <mord...@gmail.com>
Date: Wed, 4 Feb 2009 11:11:43 -0800 (PST)
Local: Wed, Feb 4 2009 2:11 pm
Subject: Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
So whats a good solution?

Rohit

On Feb 4, 11:07 am, Romain Guy <romain...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Feb 4 2009, 2:14 pm
From: Romain Guy <romain...@google.com>
Date: Wed, 4 Feb 2009 11:14:08 -0800
Local: Wed, Feb 4 2009 2:14 pm
Subject: Re: [android-developers] Re: OutOfMemoryError BitmapFactory.nativeDecodeByteArray inside Threads
Use less memory.

--
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 30   Newer >
« Back to Discussions « Newer topic     Older topic »