Well, getting mad of this issue or trying to blame something else, 
 wouldn't really benefit you, would it? Absurd as much as it is, thats most 
likely what you got.

If you're so pressed on using so much memory, you can also resolve this 
issue by allocating it in a different manner. This issue is raised because 
the heap grew to 48MB prior to allocating the offending bitmap, not because 
that bitmap is too big... if you can change the way you do things so you'll 
never get to needing 48MB at the same time, you'd avoid the issue. This is 
how i resolved it, just changed the order of things i do and used stricter 
control on my memory allocation so i'll never inflate the heap so much. If 
you have 15mb free at the moment of the crash, it might indicate that you 
never needed to increase the heap to that size anyway. Imagine you're 
playing memory sokoban :)

you can also:
 - use largeHeap=true and cross your fingers
 - use added code to limit the requested bitmap quality dependent on heap 
size. lower quality is better than crashing.
 - allocate the needed space on native memory manually. Although i haven't 
done the same, i understand that when using native your limits go up
 - Come to terms with random crashes but enjoy your HD backgrounds while 
they show:)

On Thursday, November 22, 2012 12:34:05 PM UTC+2, Fran wrote:
>
> Hi,
>
> I hardly could use less memory. Devices with high dpi  and res needs more 
> memory so they can use HD images, that's why they have a higher heap limit. 
> Now if you cannot use all that heap size... it is just absurd!
>
> I rather prefer that the problem were a bug on bugsense and this report 
> weren't reliable...
> On Nov 22, 2012 9:26 AM, "Piren" <[email protected] <javascript:>> wrote:
>
>> Yep, makes no sense at all, but thats how it is.
>> Maybe we can ask Romain to give Dianne a call and get a response :-P
>>
>> I tried finding that thread that mentioned this Dalvik bug/feature but no 
>> luck... i did come across Romain's famous "use less memory" quote :-P (
>> http://code.google.com/p/android/issues/detail?id=8488&can=1)  Which 
>> oddly, in your case does apply... As i said, the best trick i've found is 
>> just not to get the heap so large. 
>>
>>
>>
>> On Wednesday, November 21, 2012 7:31:06 PM UTC+2, Fran wrote:
>>>
>>> Hi,
>>>
>>> That has no sense at all. I do not mean that you are not right, just 
>>> mean that in such case it is a mighty bug...
>>>
>>> Best regards,
>>>
>>> 2012/11/21 Piren <[email protected]>
>>>
>>>> I remember reading about a similar issue in the past and experienced 
>>>> the same issue as well.
>>>> From what i recall, but dont take my word for it, even if there is room 
>>>> in the heap and it isnt fragmented beyond belief, Dalvik first checks if 
>>>> the heap can be enlarged to include the needed space, instead of trying to 
>>>> use the space it has free.
>>>>
>>>> Since you're already at 48MB, you've just pushed through the limit with 
>>>> the new needed allocation (regardless of the fact you have the space), and 
>>>> Dalvik throws the OutOfMemoryException.  I had it happen to me as well. 
>>>>
>>>> Only solution i've found? to never get the heap so large it sits on the 
>>>> edge (stupid bug, stupid solution, i know).
>>>>
>>>> I think Dianne Hackburn mentioned that, maybe a google search will find 
>>>> it.
>>>>
>>>>
>>>> On Wednesday, November 21, 2012 5:18:33 PM UTC+2, Fran wrote:
>>>>
>>>>>  On 11/21/2012 03:58 PM, Mark Murphy wrote:
>>>>>  
>>>>> First, you do not know necessarily what BitmapFactory.Options are 
>>>>> being specified on the decodeResource() call, as that does not appear to 
>>>>> be 
>>>>> called from your code, and it could be they have strange values in there.
>>>>>
>>>>> Well, as far as my own code reaches (AndroidGraphics.java:77), I do 
>>>>> set these options.
>>>>>
>>>>> Options options = new Options();
>>>>> options.inPreferredConfig = Config.ARGB_8888;
>>>>> options.inScaled = false;        
>>>>>
>>>>> [...]
>>>>>
>>>>> bitmap = BitmapFactory.decodeResource(**t**his.context.getResources(), 
>>>>> resourceId, options);
>>>>>
>>>>> Beyond that, last I knew, Dalvik does not have a compacting garbage 
>>>>> collector. I haven't seen a recent statement as to whether or not that 
>>>>> limitation has been fixed. If it is still the case, though, your issue 
>>>>> may 
>>>>> not so much that you are out of memory, but that there is no single 
>>>>> contiguous block that meets your needs.
>>>>>
>>>>> Well, it may happen, but the evidence on that is really weak. The game 
>>>>> has just started and it is loading the main menu screen, with only a few 
>>>>> objects in memory, so it is unlikely that in these circunstances and with 
>>>>> 15Mb of free heap an image of just 1M5 as raw ARGB_8888 will not find an 
>>>>> slot.
>>>>>
>>>>>  On Wed, Nov 21, 2012 at 9:48 AM, Francisco Marzoa 
>>>>> <[email protected]>wrote:
>>>>>
>>>>>>  Look at this:
>>>>>>
>>>>>>   0java.lang.OutOfMemoryError: (Heap Size=48547KB, Allocated=33541KB)  
>>>>>> 1at android.graphics.**BitmapFactory**.**nativeDecodeAsset(Native 
>>>>>> Method)  2at android.graphics.**BitmapFactory**.decodeResource(**
>>>>>> BitmapFactory.**java:595)  3at com.badlogic.androidgames.**fram**
>>>>>> ework.impl.**AndroidGraphics.**newPixmap(**AndroidGraphics.**java:77)  
>>>>>> 4at com.badlogic.androidgames.**fram**ework.impl.**AndroidGraphics.**
>>>>>> newPixmap(**AndroidGraphics.**java:133)  5at net.iberdroid.**
>>>>>> ruletaafortunada**core.**MainMenuScreen.**loadImages(**
>>>>>> MainMenuScreen.**java:255)  6at net.iberdroid.**ruletaafortunada**
>>>>>> core.**MainMenuScreen.enable(**Mai**nMenuScreen.java:241)  
>>>>>> The image that I am trying to load at MainMenuScreen.java:255 
>>>>>>
>>>>>> The weird thing is that there is free heap enough for loading that 
>>>>>> image: it is a 800x480 png indexed but with transparency, so I load it 
>>>>>> using four bytes per pixel (ARGB) and it should use about 1M5 of memory 
>>>>>> as 
>>>>>> a raw bitmap... but it crashes anyway trying to load an image ten times 
>>>>>> smaller the available heap space (48-35 = 15Mb).
>>>>>>
>>>>>> These things makes me crazy... 
>>>>>>
>>>>>> Bests,
>>>>>>
>>>>>>
>>>>>>
>>>>>>  -- 
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Android Developers" group.
>>>>>> To post to this group, send email to android-d...@**googlegroups.com
>>>>>>
>>>>>> To unsubscribe from this group, send email to
>>>>>> android-developers+**unsubscribe**@googlegroups.com
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/**group**/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>>>>
>>>>>  
>>>>>
>>>>>
>>>>>  -- 
>>>>> Mark Murphy (a Commons Guy)
>>>>> http://commonsware.com | http://github.com/commonsguy
>>>>> http://commonsware.com/blog | http://twitter.com/commonsguy
>>>>>
>>>>> _The Busy Coder's Guide to Android Development_ Version 4.3 Available!
>>>>>  -- 
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to android-d...@**googlegroups.com
>>>>>
>>>>> To unsubscribe from this group, send email to
>>>>> android-developers+**unsubscribe**@googlegroups.com
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/**group**/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>>>  
>>>>>
>>>>>
>>>>>   -- 
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to android-d...@**googlegroups.com
>>>> To unsubscribe from this group, send email to
>>>> android-developers+**[email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to 
>> [email protected]<javascript:>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to