什么是位图#循环()在Android的蜂窝实际上做? [英] What does Bitmap#recycle() in Android Honeycomb actually DO?

查看:114
本文介绍了什么是位图#循环()在Android的蜂窝实际上做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个非常内存密集型应用程序为Android蜂窝,而我一直非常谨慎地循环()位图 s ^尽可能;事实上,这是必要的应用程序在所有的工作,如位图 s的不断循环进出内存。但是,我刚才已经实施 onConfigurationChanged()活动,所以(对于一些原因)我试图把内存释放例程的onStop()

I am writing a very memory intensive application for Android Honeycomb, and I've been very careful to recycle() unused Bitmaps wherever possible; indeed, this is necessary for the application to work at all, as Bitmaps are constantly being cycled in and out of memory. However, I have just implemented onConfigurationChanged() in the Activity, and so (for a number of reasons) I am trying to put memory freeing routines in onStop().

目前我的的onStop()方法:

  • 设置一些查看 s到显示默认绘制对象;
  • 电话循环()位图取值previously使用这些查看 S;
  • 空引用到位图秒。
  • sets some Views to display a default Drawable;
  • calls recycle() on the Bitmaps previously used by these Views;
  • nulls references to the Bitmaps.

不幸的是,使用Eclipse内存分析器,看来这是有的内存使用没有任何影响的。

Unfortunately, using the Eclipse memory profiler, it seems this is having no effect on the memory usage at all.

你可以想像,已经做了这么多努力,以腾出资源在名义上垃圾收集的语言,我本来希望多一点影响。所以我的问题是:是什么循环()吗?它实际上引发垃圾收集,或将在系统上坚持如果调用,甚至内存的System.gc() -until它觉得需要摆脱的东西?

As you can imagine, having made so much effort to free resources in a nominally garbage-collected language, I would have hoped for a little more effect. So my question is: what does recycle() do? Does it actually trigger garbage collection, or will the system hold on to the memory—even if you call System.gc()—until it feels the need to get rid of something?

注:我知道位图 s的实际上不是在常规堆中举行,但我想打电话给循环()足以确保他们退出了本机堆。

NB I know Bitmaps aren't actually held in the regular heap but I thought calling recycle() was enough to ensure they were dropped out of the native heap.

部分答案

我发现,如果一个的ImageView 包含位图已回收的是,位图数据仍然保留在内存中,直到 setImageBitmap(空)是呼吁的ImageView 。这甚至可能是这种情况,如果 setImageResource(...) setImageDrawable(...)被称为(他们是,装在一个相对较小的九补丁然而,MAT的分析表明,这并不能消除的大位图,这是包含在<$ C $的私有成员C> ImageView的)。简单地调用这个函数在的onStop()已扑杀约从我们的应用程序的堆10MB。显然,这可能不是pre-蜂窝的情况下建立的Andr​​oid,虽然。

I have discovered that if an ImageView contains a Bitmap that has been recycled, the Bitmap data is still retained in memory until setImageBitmap(null) is called on the ImageView. This may even be the case if setImageResource(...) or setImageDrawable(...) are called (they were, loading in a relatively small nine-patch—however, MAT analysis shows this did not remove the large Bitmap, which was contained in the private members of the ImageView). Simply calling this function at onStop() has culled about 10MB from the heap of our application. Apparently this may not be the case for pre-Honeycomb builds of Android, though.

推荐答案

我发现,在蜂巢起,如果的ImageView 包含位图已回收的是,位图数据仍然保留在内存中,直到 setImageBitmap(空)被称为在ImageView的。这甚至可能是这种情况,如果 setImageResource(...) setImageDrawable(...)被称为(以这种情况下,一个非常大的位图被换成了一个相当小九的补丁,但只有当 setImageBitmap(空)加载九补丁实际上是设置在内存之前被称为)。

I have discovered that, in Honeycomb onwards, if an ImageView contains a Bitmap that has been recycled, the Bitmap data is still retained in memory until setImageBitmap(null) is called on the ImageView. This may even be the case if setImageResource(...) or setImageDrawable(...) are called (in this case, a very large bitmap was replaced with a fairly small nine-patch, but only when setImageBitmap(null) was called before loading the nine-patch was the memory actually disposed).

这篇关于什么是位图#循环()在Android的蜂窝实际上做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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