setImageResource运行内存 [英] setImageResource running out of memory

查看:314
本文介绍了setImageResource运行内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行setImageResource()每10秒(资源是JPEG文件)重复Runnable任务。这是发生活动的唯一显著的东西。

I have a repeated Runnable task that performs a setImageResource() every 10 seconds (the resource is a jpeg file). This is the only significant thing happening in the activity.

然而,经过几次迭代(2-4),应用程序崩溃,出现以下错误:

However, after a few iterations (2-4), the app crashes with the following error:


  • VM不会让我们分配X字节

  • 关闭VM

我没有想到这一点。为什么不是GC清理previous JPEG位图?如何避免崩溃虚拟机?

I did not expect this. Why isn't the GC cleaning up previous jpeg bitmaps? How do I avoid crashing the VM?

感谢。

推荐答案

您要呼吁previous位图的循环。 Android是分配用于图像的recources内存,并且不释放它,直到你调用回收方法用你的双手。

You have to call recycle on previous bitmaps. Android is allocating memory for image recources and is not freeing it until you call recycle method with your hands.

这篇关于setImageResource运行内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆