安卓位图回收:需要设置为空?

问题描述 投票:0回答:1

是否需要设置一个 Bitmapnull 回收后,使其内存得以释放?

在下面的代码中。

private static Bitmap bmpConcatHV() {
    Bitmap bmp = BitmapFactory.decodeResource(resId);
    Bitmap bmp2 = concatVertically(bmp, bmp);
    bmp.recycle();
    bmp = null;
    Bitmap bmp3 = concatHorizontally(bmp2, bmp2);
    bmp2.recycle();
    bmp2 = null;
    return bmp3;
}

Lint 警告。

分配给'bmp'的值null永远不会被使用。

分配给'bmp2'的值null永远不会被使用。

android android-bitmap recycle
1个回答
1
投票

两个 bmpbmp2 是局部变量,所以不是。


0
投票
BitmapFactory.decodeResource(resId);

bitmap在加载到内存中时有两部分信息--关于bitmap的信息==>存在于java使用的内存中2--关于bitmap像素的信息(数组的字节)==>存在于c++使用的内存中。

Bitmap.recycle()用于释放C++.Garbage Collection将收集部分java和内存。

当需要内存时,垃圾收集工作,但我现在需要使用这个参考,所以将使用。

bmp = null; here i handle the part of java and be safe to make it null
© www.soinside.com 2019 - 2024. All rights reserved.