1

In our app we have a lot of images. When they needed we get them in such way: PlayN.assets().getImage("imageURL");

In android 2.3 there is limit for 24mb of bitmap resources. So, while showing images on Screen2(let's say Game) i must hide (unload) images from Screen1(lets say Intro). I have reference to image from Screen1 and i can call clear() method: CanvaseImage referenceToImage - i need to unload, referenceToImage.canvas().clear();

BUT, - this way do not unload image from android memory in 2.3.x - ( Android: Bitmap recycle() how does it work?... this post tell that i should call recycle() on bitmap, since bitmaps are stored in non-management memory and cant be shrinked from there by GC.)

and i have such stackTrace for android if images from Screen1 are not unloaded from memory:

06-11 09:16:45.197: E/AndroidRuntime(23621): FATAL EXCEPTION: GLThread 
10 
06-11 09:16:45.197: E/AndroidRuntime(23621): 
java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap 
Size=9479KB, Allocated=6032KB, Bitmap Size=23347KB) 
06-11 09:16:45.197: E/AndroidRuntime(23621):    at 
android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 
06-11 09:16:45.197: E/AndroidRuntime(23621):    at 
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:694) 
06-11 09:16:45.197: E/AndroidRuntime(23621):    at 
playn.android.AndroidAssets.decodeBitmap(AndroidAssets.java:158) 
06-11 09:16:45.197: E/AndroidRuntime(23621):    at 
playn.android.AndroidAssets.doGetImage(AndroidAssets.java:79) 
06-11 09:16:45.197: E/AndroidRuntime(23621):    at 
playn.core.AbstractAssets.getImage(AbstractAssets.java:39) 

Is there some way to call playN 's magic for recycling bitmaps in Android 2.3.x memory model?

Community
  • 1
  • 1

2 Answers2

1

Have you already taken a look at the Google article about memory managment? They really give a fairly in depth explanation of how to deal with that bitmap issue.

MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
1

why don't you use LruCache for caching bitmaps? see article here

Buda Gavril
  • 21,409
  • 40
  • 127
  • 196