Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 跟踪内存泄漏-位图_Android_Image_Memory Leaks_Bitmap_Mat - Fatal编程技术网

Android 跟踪内存泄漏-位图

Android 跟踪内存泄漏-位图,android,image,memory-leaks,bitmap,mat,Android,Image,Memory Leaks,Bitmap,Mat,我在跟踪我的应用程序中的内存泄漏时遇到问题。 我正在使用MAT来做这件事,但我也是这个功能的初学者,所以我需要你的帮助 支配树如下所示: 显然,位图的23%是不正常的 GC根目录的路径->排除弱引用: 但我真的不知道下一步该怎么办。。。很明显,内存正在图像中泄漏 我正在将资源转换为位图,并按如下方式进行缩放: private Bitmap getBitmapFromRes(int resId) { Bitmap tmp = null; Bitmap b = null;

我在跟踪我的应用程序中的内存泄漏时遇到问题。 我正在使用MAT来做这件事,但我也是这个功能的初学者,所以我需要你的帮助

支配树如下所示:

显然,位图的23%是不正常的

GC根目录的路径->排除弱引用:

但我真的不知道下一步该怎么办。。。很明显,内存正在图像中泄漏

我正在将资源转换为位图,并按如下方式进行缩放:

private Bitmap getBitmapFromRes(int resId) {
    Bitmap tmp = null;
    Bitmap b = null;
    try {
        // Decode image size
        final int REQUIRED_SIZE = 70;
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        int scale = 1;

        while (o.outWidth / scale / 2 >= REQUIRED_SIZE
                && o.outHeight / scale / 2 >= REQUIRED_SIZE)
            scale *= 2;

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        InputStream fis = context.getResources().openRawResource(resId);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (tmp != null) {
            tmp.recycle();
            tmp = null;
        }
    }
    return b;
}

感谢您的帮助,并为我的英语感到抱歉…

您是否在清单文件中使用了android:largeHeap=“true”否我不是。。。显然,我不确定那是个好主意。。在这个视频()智者警告不要使用。。。我相信他:)