hi i am trying to generate dynamic layout at runtime, so i uses so 15 images for that but while loading this layout it crashes and display following error
java.lang.OutOfMemoryError: bitma开发者_StackOverflowp size exceeds VM budget
04-07 16:07:35.465: ERROR/dalvikvm-heap(547): 85100-byte external allocation too large for this process.
so what should i do for managing memory? thanx
Looks like you are loading big images without resizing them. See Strange out of memory issue while loading an image to a Bitmap object
OutofMemory
error occurs when your App exceeds the default allowed storage usage (Heap size) in Android. The max allowed heap size is 24 MB for every program. Hence when you try to load more multi media elements, it would pile your heap, causing OOM exception. This size can be extended by giving the parameter android:largeHeap="true"
(more details here).
Though it is possible, it is not recommended to increase your heap size because it delay the garbage collection time.
For you the immediate solution would be to just resize the images and continue, provided you don't load too many more later.
Or a more efficient solution would be understand how and what is happening. Try to learn about memory allocation from developer website and this video from Google will help too.
精彩评论