Piasy / BigImageViewer

Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻
MIT License
3.98k stars 402 forks source link

Memory leak at the sample app's RecyclerViewActivity #124

Closed Tobibur closed 5 years ago

Tobibur commented 6 years ago

This is a very nice & useful library you made. I was checking the sample app and got this memory leak notification.

Piasy commented 6 years ago

Hi, I'm busy these days, could you please do some investigation about this problem? PR is welcome!

xujiaji commented 5 years ago

我是在自定义Application中创建一个方法通过反射清理掉引用,在对应的Activity的onDestroy生命周期调用一下cleanGlideLoading()

    public void cleanGlideLoading() {
        Field mRequestTargetMap = null;
        try {
            mRequestTargetMap = mGlideImageLoader.getClass().getDeclaredField("mRequestTargetMap");
            mRequestTargetMap.setAccessible(true);
            Map map = (Map) mRequestTargetMap.get(mGlideImageLoader);
            map.clear();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
Piasy commented 5 years ago

@xujiaji 可以考虑为 ImageLoader 增加一个接口,用于显式清理资源,供使用者调用。欢迎提交 PR。