Question

I am loading 3d models (1MB - 10MB) into memory which takes a long time (20 sec for 1.5MB model). When I look at the logs I see that the garbage collector constantly frees memory and pauses. See below for the logs:

07-20 17:37:25.340: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 8% free 79443K/85575K, paused 86ms
07-20 17:37:25.350: I/dalvikvm-heap(2826): Grow heap (frag case) to 78.511MB for 852408-byte allocation
07-20 17:37:25.450: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 8% free 80275K/86471K, paused 95ms
07-20 17:37:25.550: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 8% free 80275K/86471K, paused 85ms
07-20 17:37:25.550: I/dalvikvm-heap(2826): Grow heap (frag case) to 79.325MB for 852408-byte allocation
07-20 17:37:25.660: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 8% free 81108K/87367K, paused 96ms
07-20 17:37:25.760: D/dalvikvm(2826): GC_FOR_ALLOC freed 0K, 8% free 81108K/87367K, paused 87ms
07-20 17:37:25.760: I/dalvikvm-heap(2826): Grow heap (frag case) to 80.137MB for 852408-byte allocation
07-20 17:37:25.870: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 8% free 81940K/88263K, paused 98ms
07-20 17:37:26.060: D/dalvikvm(2826): GC_CONCURRENT freed <1K, 5% free 83988K/88263K, paused 3ms+12ms
07-20 17:37:26.200: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 5% free 84715K/88263K, paused 120ms
07-20 17:37:26.200: I/dalvikvm-heap(2826): Grow heap (frag case) to 83.660MB for 852312-byte allocation
07-20 17:37:26.310: D/dalvikvm(2826): GC_FOR_ALLOC freed 0K, 5% free 85547K/89159K, paused 102ms
07-20 17:37:26.420: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 5% free 85547K/89159K, paused 95ms
07-20 17:37:26.420: I/dalvikvm-heap(2826): Grow heap (frag case) to 84.473MB for 852312-byte allocation
07-20 17:37:26.520: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 5% free 86379K/90055K, paused 105ms
07-20 17:37:26.640: D/dalvikvm(2826): GC_FOR_ALLOC freed <1K, 4% free 87212K/90055K, paused 117ms
07-20 17:37:26.650: I/dalvikvm-heap(2826): Grow heap (frag case) to 86.098MB for 852312-byte allocation
...

Is it possible to postpone the garbage collection until after the model is loaded. Any other performance tips are welcome as well :)

Was it helpful?

Solution

No, this is not possible, the virtual machine handles this and it's not changeable. But to speed up loading the models you could consider using serialized objects instead of the .3ds/.obj/... files. They will load faster and use less memory.

Check the wiki about jpct and serialized objects.

OTHER TIPS

No, you can't postpone garbage collection or control it in any other way.

But you can use Allocation Tracker from DDMS to find where exactly you are creating new objects. Try to reuse the same objects and buffers, avoid auto-boxing, etc. This article about using Allocation Tracker may be helpful.

no.

anyway, if you notice in the logs, the VM is struggling for memory. it has ~5% free. it has to perform a GC to keep running your app.

moreover, you don't want to do that if you could. intelligent people have developed optimal garbage collection algorithms over decades. don't try to me smarter than them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top