Wednesday, May 23, 2012

Android bitmap out of memory error

I get the famous out of memory error. But i have tried many of the suggested solutions on this problem without any luck. I understand that to prevent a bitmap to exceed the memory, you make a static variable of the drawable (Android docs). But that isn't working in my app because i have so many markers as you can see..

Does anyone have a suggestion to a solution?

for(Poi p : poiarray){

WeakReference<Bitmap> bitmap = new WeakReference<Bitmap>(p.get_poiIcon());

Drawable marker = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap.get(), 60, 60, true));
annotationOverLays.add(new CustomAnnotation(marker,p,this,mapView));
//mapView.getOverlays().add(new CustomAnnotation(marker,p,this,mapView));


05-23 13:08:31.436: E/dalvikvm-heap(22310): 20736-byte external allocation too large for this process.
05-23 13:08:31.436: E/dalvikvm(22310): Out of memory: Heap Size=23111KB, Allocated=22474KB, Bitmap Size=1505KB
05-23 13:08:31.436: E/GraphicsJNI(22310): VM won't let us allocate 20736 bytes

No comments:

Post a Comment