释放连接到ImageView的位图 [英] Releasing a bitmap attached to an ImageView

查看:228
本文介绍了释放连接到ImageView的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本活动(SherlockActivity子类),它加载视图有一个单一的,最大规模的ImageView。

I have a basic activity (SherlockActivity subclass), and the view it loads has a single, max-sized ImageView.

<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:orientation="vertical"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="fill_parent"
    p1:layout_height="fill_parent"
    p1:id="@+id/linearLayout1">
    <ImageView
        p1:src="@android:drawable/ic_menu_gallery"
        p1:layout_width="fill_parent"
        p1:layout_height="fill_parent"
        p1:id="@+id/imageView"
        p1:scaleType="fitCenter" />
</LinearLayout>

活动做的唯一一件事就是加载一个位图,并将其分配到的ImageView

The only thing the Activity does is load a Bitmap and assign it to the ImageView

var iv = FindViewById<ImageView>(Resource.Id.imageView);
iv.SetBitmapImage(BitmapFactory.decodeFile(file....))

在我计算出如何调整负载位图(的http:/ /developer.android.com/training/displaying-bitmaps/load-bitmap.html ),这是每一个我装了活动时间嚼起来5MB的内存,直到应用程序崩溃(现在没有,但我觉得这个问题还是存在的)。即使我这样做是这样的:

Before I worked out how to resize bitmaps on load ( http://developer.android.com/training/displaying-bitmaps/load-bitmap.html ) this was chewing up 5MB of memory each time I loaded the activity, until the app crashed (now it doesn't, but I think this problem is still there). Even if I did it like this:


  • 在父活动,点击按钮打开子

  • 在子(上面的图片查看)点击返回

  • 在父母,子女开放

  • 在孩子,点击返回

  • 等等等等,直到它崩溃(约4倍左右,因为它是5MB每次!)

因此,实际的问题:要不要我来处理图像时,活动停止或者被破坏?我想在Java中 - 或C# - 事情GC'ed,所以我并不需要做。我缺少的活动周期的东西吗?

这两个答案的作者终于想出了正确的答案(GC的这样做,但你可以回收(强制),因此标识正确的其中一个有它的答案,所以它更容易找到其他

推荐答案

尝试调用循环()的位图。

http://developer.android.com/reference/android/graphics/Bitmap.html#recycle%28%29

这篇关于释放连接到ImageView的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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