0

i'm recycling large bitmap files for my game in hopes of avoiding out of memory errors. however the system does not appear to be making the memory available for new bitmap allocation no matter how many bitmaps I recycle. it always appears to crash at the same time as if I didn't recycle anything. I'm using system.gc to force garbage collection after every recycle command, but it doesn't seem to make a difference. neither does view.getResources().flushLayoutCache(); or view.destroyDrawingCache();.

here is the log before the crash:

02-12 16:24:45.006: D/dalvikvm(1627): GC_EXPLICIT freed 3113K, 20% free 25450K/31751K, paused 77ms+47ms
02-12 16:24:45.006: D/MainGamePanel(1627): system.gc called

02-12 16:24:46.966: D/dalvikvm(1627): GC_CONCURRENT freed <1K, 14% free 27403K/31751K, paused 35ms+140ms

02-12 16:24:52.975: D/dalvikvm(1627): GC_CONCURRENT freed 2546K, 16% free 26871K/31751K, paused 60ms+91ms

02-12 16:25:35.253: D/dalvikvm(1627): GC_CONCURRENT freed 1742K, 15% free 27138K/31751K, paused 51ms+44ms

02-12 16:26:38.351: D/dalvikvm(1627): GC_CONCURRENT freed 1923K, 15% free 27226K/31751K, paused 87ms+69ms

02-12 16:28:03.941: D/dalvikvm(1627): GC_CONCURRENT freed 3577K, 20% free 25696K/31751K, paused 26ms+57ms

02-12 16:28:08.879: D/Datapool(1627): recycle called

02-12 16:28:10.356: D/dalvikvm(1627): GC_EXPLICIT freed 934K, 20% free 25578K/31751K, paused 73ms+73ms

02-12 16:28:10.356: D/Datapool(1627): system.gc called

02-12 16:28:12.356: D/dalvikvm(1627): GC_EXPLICIT freed 732K, 22% free 24845K/31751K, paused 60ms+66ms

02-12 16:28:12.356: D/Datapool(1627): system.gc called

02-12 16:28:13.536: D/dalvikvm(1627): GC_FOR_ALLOC freed 85K, 23% free 24760K/31751K, paused 1128ms

02-12 16:28:13.756: I/dalvikvm-heap(1627): Grow heap (frag case) to 26.915MB for 2797584-byte allocation

02-12 16:28:15.486: D/dalvikvm(1627): GC_CONCURRENT freed 0K, 14% free 27492K/31751K, paused 79ms+114ms

02-12 16:28:17.428: D/dalvikvm(1627): GC_FOR_ALLOC freed 0K, 14% free 27492K/31751K, paused 649ms

02-12 16:28:17.428: I/dalvikvm-heap(1627): Forcing collection of SoftReferences for 1243076-byte allocation

02-12 16:28:18.715: D/dalvikvm(1627): GC_BEFORE_OOM freed 0K, 14% free 27492K/31751K, paused 1276ms

02-12 16:28:18.715: E/dalvikvm-heap(1627): Out of memory on a 1243076-byte allocation.

trincot
  • 317,000
  • 35
  • 244
  • 286
Androidcoder
  • 4,389
  • 5
  • 35
  • 50

1 Answers1

1

If it was possible you could try to change the gc algorithm that the dalvikVM implements. But I think this is not an option. The dalvik implements the mark and sweep

I've seem some threads about problems with images.

One snippet called my attention:

try this as soon as the image is dereferenced:

 bitmap.recycle();
    System.gc();
    Runtime.getRuntime().gc(); 

This thread is very complete about image management.

Strange out of memory issue while loading an image to a Bitmap object

Community
  • 1
  • 1
Eduardo Briguenti Vieira
  • 4,351
  • 3
  • 37
  • 49