I don't think it compacts. Androids approach to reducing fragmentation
is "kill the app and restart it" :( You could try serializing the
important state, then clearing absolutely everything from the heap and
reconstructing the internals from the serialized state.

On Jun 7, 11:05 am, Keith Wiley <kbwi...@gmail.com> wrote:
> I'll give that some thought, it's not a bad idea.  However, 65k
> strikes me as a very small request, even contiguously.  Will the Java
> (or Dalvik) garbage collector defragment the memory at all or will it
> just stay fragmented indefinitely (until I reallocate things into
> large blocks)?
>
> On Jun 6, 6:14 pm, Mark Murphy <mmur...@commonsware.com> wrote:
>
> > Keith Wiley wrote:
> > > My app is building a relatively large structure ("large" being a term
> > > that is meaningless without context), and I am getting an
> > > OutOfMemoryError.  Problem is, I'm watching the memory using every
> > > metric I can think of, and I don't see how the error was triggered.
> > > It's obviously trying to allocate a 65kB HashSet in a rehash
> > > operation:
>
> > > 06-06 17:59:11.234: ERROR/dalvikvm-heap(1884): Out of memory on a
> > > 65552-byte allocation.
>
> > > Which makes sense; I traced it to the HashSet operation it is
> > > performing.  But this is what the memory looks at:
>
> > > ActivityManager.Memory Info: availMem: 26300416B, 26300KB, 26MB
> > > ActivityManager.Memory Info: threshold/lowMemory: 16777216  false
> > > Runtime.freeMemory: 1828856B, 1829KB, 2MB
> > > Runtime.totalMemory: 15605728B, 15606KB, 16MB
> > > Debug memory allocated/native/default: 4452208  1032336  5484544
>
> > > I don't get it.  Why won't it make a measly 65kB heap?  How can I
> > > detect memory problems given these utilities if they always return
> > > extremely large values right before and after an OutOfMemoryError?
> > > Are there yet additional memory utilities I should be using?
>
> > It may be a fragmentation issue. If I understand correctly, if you do
> > lots and lots of reallocations, while you may have tons of memory free,
> > there may not be a 65552-byte buffer free.
>
> > Can you pre-allocate your HashSet to a nice large capacity up front, to
> > avoid the reallocations?
>
> > --
> > Mark Murphy (a Commons 
> > Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > Need Android talent? Ask on HADO!http://wiki.andmob.org/hado
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to