没有位图回收调用的位图回收错误

时间:2014-11-26 17:14:04

标签: android bitmap

我有一个适配器可以将图像加载到视图中。它运行正常,但是当我通过在列表视图中上下快速滚动来测试ListView时,我得到一个" Canvas尝试使用循环位图"。但是我从不调用bitmap.recycle,因为我使用的是imageloader。该错误未向我提供错误发生位置的位置。我的猜测是适配器会自动回收位图,因为我没有进行手动调用。这个问题不是很一致,但如果我真的尝试,我可以重新创建它。是什么导致了这个问题,或者我如何找到它?

这是堆栈跟踪。

11-26 11:01:41.131    1124-1124/com.android.wallfly E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.android.wallfly, PID: 1124
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@432bc210
        at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1084)
        at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:844)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:496)
        at android.widget.ImageView.onDraw(ImageView.java:1058)
        at android.view.View.draw(View.java:15304)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.getDisplayList(View.java:14193)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.draw(View.java:15307)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.draw(View.java:15307)
        at android.widget.FrameLayout.draw(FrameLayout.java:472)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.widget.ListView.drawChild(ListView.java:3393)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.widget.AbsListView.dispatchDraw(AbsListView.java:2918)
        at android.widget.ListView.dispatchDraw(ListView.java:3388)
        at android.view.View.draw(View.java:15307)
        at android.widget.AbsListView.draw(AbsListView.java:5184)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3272)
        at android.view.View.getDisplayList(View.java:14135)
        at android.view.View.getDisplayList(View.java:14240)

这是ImageLoader信息

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new WeakMemoryCache())
            .diskCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .writeDebugLogs() // Remove for release app
            .build();

            options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisc(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .resetViewBeforeLoading(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                .build();

2 个答案:

答案 0 :(得分:1)

您的ImageLoader显然正在进行一些回收。

要更好地了解问题,请参阅Android trying to use a recycled bitmap, not in my codeCanvas: trying to use a recycled bitmap android.graphics.Bitmap in android

如何修复它取决于您的实施(代码)和您的"图像加载器"。 发布一些代码或StackTrace可能有所帮助。

答案 1 :(得分:0)

请删除

<块引用>

bitmap.recycle();

来自您的代码。它将解决您的错误。