与通用图像装载机查看传呼机内存不足错误 [英] View Pager with Universal Image Loader Out of Memory Error

查看:167
本文介绍了与通用图像装载机查看传呼机内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道,如果一个ViewPager与通用图像装载机可/应作为一个备用的一样的界面,画廊,因为我遇到了一个内存错误而载入图像从SD卡并观看全屏模式。无论是什么号码,它工作一切优秀与GridView控件,但在观看了查看传呼机的图像,每个位图保持吃了大量的内存和10个左右影像后,它给了内存不足的错误。

我看到,几乎所有已张贴在这里,同时与通用图像装载机和他们每个人的工作涉及到内存不足错误的问题,出现了配置错误的原因。

我不知道如果我使用了错误的配置或什么,但我已经浪费了很多时间在上面,并也有点卡住,任何帮助/意见将是AP preciated。

的配置为ImageLoader的:

  ImageLoaderConfiguration配置=新ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(新WeakMemoryCache())
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(新Md5FileNameGenerator())
            .imageDownloader(新ExtendedImageDownloader(getApplicationContext()))
            .tasksProcessingOrder(QueueProcessingType.LIFO)
// .enableLogging()//没有必要共同
            。建立();
 

显示图像的选项有:

 选项=新DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.image_for_empty_url)
            .resetViewBeforeLoading()
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(新FadeInBitmapDisplayer(300))
            。建立();
 

我使用的是赋予了与库,但这些设置不会擦出火花,一段时间后,它只是崩溃的例子项目。我的猜测是,有一个具体的回调,我有回收从不可见的看法位图。

编辑:我知道它的内存泄漏,不可见的美景被破坏时,他们应该是,但不会释放内存,因为它应该。继承人的destroyItem回调的执行,遵循不同的问题给出的提示,但仍然无法找到内存泄漏。

  @覆盖
        公共无效destroyItem(View容器,INT位置,Object对象){
//((ViewPager)容器).removeView((查看)对象);
            Log.d(消灭,破坏观点在位置+位置);
            查看查看=(查看)对象;
            ((ViewPager)容器).removeView(视图);
            鉴于= NULL;
        }
 

解决方案

尝试应用下一个建议:

  1. 使用 ImageScaleType.EXACTLY
  2. 启用缓存盘上(在显示选项)。
  3. 最后尝试使用 .discCacheExtraOptions(maxImageWidthForDiscCache,maxImageHeightForDiscCache,COM pressFormat.PNG,0)

I am not really sure if a ViewPager with Universal Image Loader can/should be used as an alternate for a gallery like interface since I have run into an Out of Memory error while loading images from SD Card and viewing them in full screen mode. No matter what the number, it works all fine with a GridView but while viewing the images in the View Pager, each bitmap keeps eating up a lot of memory and after 10 or so images, it gives the out of memory error.

I have seen almost all the questions that have been posted here related to the Out of Memory Error while working with the Universal Image Loader and in each one of them, there has been a configurations error as the cause.

I dont know if I am using the wrong configurations or what but I have wasted a lot of time on it and am kind of stuck, any help/advice would be appreciated.

The configurations for the ImageLoader:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(new WeakMemoryCache())
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .imageDownloader(new ExtendedImageDownloader(getApplicationContext()))
            .tasksProcessingOrder(QueueProcessingType.LIFO)
//          .enableLogging() // Not necessary in common
            .build();

The Display Image Options are:

options = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.image_for_empty_url)
            .resetViewBeforeLoading()
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(300))
            .build();

I am using the example project that was given with the library but those settings wont work either, it just crashes after some time. My guess is that there is a specific callback where I have to recycle bitmaps from the views from that are not visible.

EDIT: I know its a memory leak, the views that are not visible are destroyed when they should be but the memory is not released as it should. Heres the implementation of the destroyItem callback, followed the tips given in different questions but still cant find the memory leak.

@Override
        public void destroyItem(View container, int position, Object object) {
//          ((ViewPager) container).removeView((View) object);
            Log.d("DESTROY", "destroying view at position " + position);
            View view = (View)object;
            ((ViewPager) container).removeView(view);
            view = null;
        }

解决方案

Try to apply next suggestions:

  1. Use ImageScaleType.EXACTLY
  2. Enable caching on disc (in display options).
  3. Finally try to use .discCacheExtraOptions(maxImageWidthForDiscCache, maxImageHeightForDiscCache, CompressFormat.PNG, 0);

这篇关于与通用图像装载机查看传呼机内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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