Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Out of memory - despite being way under 16mb
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
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
Sheado  
View profile  
 More options Feb 24 2011, 3:42 pm
From: Sheado <chad...@gmail.com>
Date: Thu, 24 Feb 2011 12:42:29 -0800 (PST)
Local: Thurs, Feb 24 2011 3:42 pm
Subject: Out of memory - despite being way under 16mb
Hello. I tried posting this earlier, but it didn't seem to stick (so
sorry if it double posts).

My app occasionally runs out of memory when loading bitmaps. I call
recycle() on every bitmap I'm done with and even set them to null.

As far as diagnostics:
* I ran ddms and never saw the heap go over 5.5mb. The largest image I
load is 480x320, so there's no way that pushing it over the 16mb
limit.
* I dumped the event log and noticed this at one point:
I/dvm_gc_info( 6655):
[7290888427799873005,-9036888781628737488,-3939943202692585437,9505022]
According to somebody else's post this could be bad (sorry I lost the
link to that post). (gdb) print (0xtop12 & 0x1ff) << ((0xbottom12 >>
9) * 4)  ==> resulting in greater than 17mb
* to confirm this, I dump hprof and analyzed it with Eclipse Mat, but
all I saw was a peak usage of 2.1mb and a suspected leak of 700k
* Scouring the forums, I found this:
http://groups.google.com/group/android-developers/browse_thread/threa...
Could my problem really be due to memory fragmentation? My app does
load and unload(recycle) bitmaps often.

I don't know which of these to believe and what to do to prevent these
out of memory exceptions from ever happening again - or at the very
least I'd like to properly interpret the data I'm getting from these
logs and profilers.

any advice would be awesome!
thanks.


 
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.
android777  
View profile  
 More options Feb 25 2011, 11:07 am
From: android777 <anilreddy...@gmail.com>
Date: Fri, 25 Feb 2011 08:07:45 -0800 (PST)
Local: Fri, Feb 25 2011 11:07 am
Subject: Re: Out of memory - despite being way under 16mb
Can you post your code? It is easier to find what's happening in that
way.

On Feb 24, 2:42 pm, Sheado <chad...@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.
Dianne Hackborn  
View profile   Translate to Translated (View Original)
 More options Feb 25 2011, 12:14 pm
From: Dianne Hackborn <hack...@android.com>
Date: Fri, 25 Feb 2011 09:14:37 -0800
Local: Fri, Feb 25 2011 12:14 pm
Subject: Re: [android-developers] Out of memory - despite being way under 16mb

Memory fragmentation does not cause this; the Dalvik heap limit is enforced
based on the actual active allocations.

Note that bitmaps are NOT include in the Dalvik heap based on what ddms
reports, but they are included in the heap limit, so most likely you have a
lot of bitmap data.

(In HC this is changed and bitmap data is now allocated directly on the
Dalvik heap.)

--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  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.
Sheado  
View profile  
 More options Feb 25 2011, 3:12 pm
From: Sheado <chad...@gmail.com>
Date: Fri, 25 Feb 2011 12:12:29 -0800 (PST)
Local: Fri, Feb 25 2011 3:12 pm
Subject: Re: Out of memory - despite being way under 16mb
Thanks for the responses.

android777 - Unfortunately it's a lot of code, but I pretty much just
load my bitmaps, and later on just call .recycle() on them. It's
possible there's a bug and some of the .recycle() calls aren't being
reached and I'm having a hard time tracking them down using profiling
tools.

Dianne - that explains a lot, thank you. Is there any way to get an
accurate (bitmap included) picture of the heap in pre-honeycomb builds
of an app?

On Feb 25, 9:14 am, Dianne Hackborn <hack...@android.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.
String  
View profile   Translate to Translated (View Original)
 More options Feb 25 2011, 6:07 pm
From: String <sterling.ud...@googlemail.com>
Date: Fri, 25 Feb 2011 15:07:18 -0800 (PST)
Local: Fri, Feb 25 2011 6:07 pm
Subject: Re: Out of memory - despite being way under 16mb

Sounds to me like you are probably hitting the bitmap deallocation problem:
http://code.google.com/p/android/issues/detail?id=8488

In summary, the issue is that bitmap memory takes several GC passes to deallocate, so it's really easy to get ahead of the GC and run out of memory.

AFAIK, there's no fix. You can help the situation somewhat by calling System.gc() after every Bitmap.recycle() call, and again before every bitmap allocation. But that's only somewhat. I've also found that setting bitmap variables to null after recycling them makes matters worse, but YMMV.

String


 
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.
Chad Ata  
View profile  
 More options Feb 25 2011, 7:03 pm
From: Chad Ata <chad...@gmail.com>
Date: Fri, 25 Feb 2011 16:03:25 -0800
Local: Fri, Feb 25 2011 7:03 pm
Subject: Re: [android-developers] Re: Out of memory - despite being way under 16mb

Thanks for that link String.
I'll look into calling System.gc() - I've always thought (and read posts
warning against it) it was bad practice to do so on Android. But I'll do it
anyway if it fixes my problem =]

-Sheado

On Fri, Feb 25, 2011 at 3:07 PM, String <sterling.ud...@googlemail.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.
Indicator Veritatis  
View profile  
 More options Feb 25 2011, 9:08 pm
From: Indicator Veritatis <mej1...@yahoo.com>
Date: Fri, 25 Feb 2011 18:08:51 -0800 (PST)
Local: Fri, Feb 25 2011 9:08 pm
Subject: Re: Out of memory - despite being way under 16mb
It is also interesting to notice: according to the official
documentation for Android Java at developer.android.com, System.gc()
is only a hint; it is no guarantee that garbage collection will
actually take place.

That said, people have told me that the hint is usually taken.

On Feb 25, 3:07 pm, String <sterling.ud...@googlemail.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.
seanw  
View profile  
 More options Feb 26 2011, 5:35 am
From: seanw <bitshift...@googlemail.com>
Date: Sat, 26 Feb 2011 02:35:27 -0800 (PST)
Local: Sat, Feb 26 2011 5:35 am
Subject: Re: Out of memory - despite being way under 16mb

On Friday, February 25, 2011 8:12:29 PM UTC, Sheado wrote:

> ...

Dianne - that explains a lot, thank you. Is there any way to get an

> accurate (bitmap included) picture of the heap in pre-honeycomb builds
> of an app?

Hi,

You can use these functions;

Runtime.getRuntime().totalMemory()
android.os.Debug.getNativeHeapAllocatedSize())

The first one tells you how much memory is being used on the Dalvik heap and
the second one tells you how much is being used on the native heap.

Regards,

Sean


 
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.
lbendlin  
View profile  
 More options Feb 26 2011, 2:26 pm
From: lbendlin <l...@bendlin.us>
Date: Sat, 26 Feb 2011 11:26:39 -0800 (PST)
Local: Sat, Feb 26 2011 2:26 pm
Subject: Re: Out of memory - despite being way under 16mb
I have an even more frustrating version of that bug. We use a mapview
that supports rotation and thus is slightly larger than the screen
area.  When users zoom in a few times they can very easily cause the
OOM condition.   I have no control over the way the Google Maps API
works, do I?

By the way, OOM is catchable. Not that it would help much though...

Here's my current code

            public void onClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                System.gc();
                try {
                    mMapView.getController().zoomIn();
                } catch (OutOfMemoryError e) {
                    e.printStackTrace();
                }
                System.gc();
                zoomLevel = mMapView.getZoomLevel();
                SharedPreferences.Editor editor = settings.edit();
                editor.putInt("zoomLevel", zoomLevel);
                editor.commit();

            }

On Feb 25, 6:07 pm, String <sterling.ud...@googlemail.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.
Chad Ata  
View profile  
 More options Mar 2 2011, 3:04 am
From: Chad Ata <chad...@gmail.com>
Date: Wed, 2 Mar 2011 00:04:16 -0800
Local: Wed, Mar 2 2011 3:04 am
Subject: Re: [android-developers] Re: Out of memory - despite being way under 16mb

Awesome,
Thanks Sean - I'll definitely try that out.


 
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.
End of messages
« Back to Discussions « Newer topic     Older topic »