如何解决Android应用程序内存不足错误
我有一个自定义列表视图。我列出了大约 200 张图像。这些图像存储在我的可绘制对象中。我已将图像转换为位图,并将图像显示为位图。每次打开活动时,都会列出图像。像这样,当我调用该活动大约 10 次时,它崩溃了,然后错误是
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
我回收了位图,并通过使用 System.gs 函数,我得到了以下内容
Clamp target GC heap from 25.464MB to 24.000MB
GC freed 322 objects / 70664 bytes in 146ms
Clamp target GC heap from 25.471MB to 24.000MB
GC freed 2 objects / 48 bytes in 138ms
Forcing collection of SoftReferences for 10720-byte allocation
Clamp target GC heap from 25.269MB to 24.000MB
DEBUG/dalvikvm(15311): GC freed 5080 objects / 211168 bytes in 121ms
ERROR/dalvikvm-heap(15311): Out of memory on a 10720-byte allocation
现在我终于得到了这个 Out of memory on a 10720-字节分配
错误
现在如何解决该错误,请朋友们帮忙
i have a custom list view. in that i am listing out images of around 200. The images are been stored in my drawable. I have converted the image to be a bitmap and i am displaying the image as bitmap. Every time when the activity is being opened the images get listed out. Like this when i am calling the activity for around 10 times it gets crashed and the error is
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
then i recycled the bitmaps and by using System.gs function i got the following
Clamp target GC heap from 25.464MB to 24.000MB
GC freed 322 objects / 70664 bytes in 146ms
Clamp target GC heap from 25.471MB to 24.000MB
GC freed 2 objects / 48 bytes in 138ms
Forcing collection of SoftReferences for 10720-byte allocation
Clamp target GC heap from 25.269MB to 24.000MB
DEBUG/dalvikvm(15311): GC freed 5080 objects / 211168 bytes in 121ms
ERROR/dalvikvm-heap(15311): Out of memory on a 10720-byte allocation
Now atlast i got this Out of memory on a 10720-byte allocation
error
Now how to resolve the error, please help me friends
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们检查一下您的情况的清单:
让我想出一些可能有用的内容并稍后添加
Let's run through the checklist for your situation:
Let me think up some more that might be helpful and add later
您是否尝试过将位图变量设置为软引用?
Have you tried setting the Bitmap variables as Soft-references?