There's quite a big discussion of this bug somewhere hidden in the bug reports, i've come across the issue myself and found its rather easy to replicate.
basically just write a loop that allocate a whole boat load of memory. run it till it poops on you then limit it to do a bit less iterations. that way the heap size will grow to very close to the top limit. then drop all the objects to free up the heap (you can even force a GC). wait a short while to see the heap is truely cleared, then allocate a big object (big enough to pass the difference between Total and Max heap size but smaller than the free heap space). see the world come down and say "WTF?" basically they check memory allocation against the total heap size instead of the free heap size. Maybe because its easier to compare an int value than to assume there's space, than fail to find sufficient space due to fragmentation.. it could be they did it on purpose just to speed up memory allocations. (since they dont support defragmentation either... which is also why they dont support heap size reductions) On Thursday, March 14, 2013 4:56:37 PM UTC+2, Kristopher Micinski wrote: > > Is that really the case? I haven't seen any Dalvik bug reports on > this, could you manage to point one out, or at least a post / example > backing this up..? > > Kris > > On Thu, Mar 14, 2013 at 10:43 AM, Piren <[email protected] <javascript:>> > wrote: > > As far as i know it's actually a bug in android, as the allocation issue > is > > in the JVM, not the kernel. > > > > Do notice that i wasn't talking about fragmentation or reaching the heap > > size limit... If your heap size is 23.9MB with 100% of it free (thus, > plenty > > of room), i.e 0MB utilization with 23.9MB of FREE heap, it will still > failon > > the next allocation of anything above 100KB (you could allocate 99KB > many > > times, but the first 100KB will fail) > > > > > > On Thursday, March 14, 2013 3:58:56 PM UTC+2, Kristopher Micinski wrote: > >> > >> On Thu, Mar 14, 2013 at 4:15 AM, Piren <[email protected]> wrote: > >> > Actually even 5K can crash his app... it all depends on what he did > >> > before > >> > the allocation. > >> > Android has a nasty bug of claiming you dont have enough memory even > if > >> > your > >> > heap has more than enough free space if it grew close to its maximum > >> > value > >> > previously (and dont't forget fragmentation as well, 10MB of free > heap > >> > doesn't mean you can allocate 10MB). > >> > >> Notice that I said "heap size" and not individual allocation because > >> of this :-). This is nothing specific to Andorid: Linux does this > >> too. > > > > -- > > -- > > 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 unsubscribe from this group and stop receiving emails from it, send > an > > email to [email protected] <javascript:>. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

