使用从UIL加载的图像切换到Fragment时出现内存不足错误

时间:2015-01-29 21:19:57

标签: java android android-fragments android-listview universal-image-loader

我有一个FragmentActivity,它是我在菜单之间切换的片段。用于在片段之间切换的代码如下:

public void changeFragment(Fragment targetFragment){
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.main_fragment, targetFragment, "fragment")
                .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.fade_in, android.R.anim.fade_out)
                .addToBackStack(null)
                .commit();
    }

每个片段都包含一个列表视图,该视图具有一个自定义适配器,该适配器显示在每个列表行上使用Universal Image Loader加载的图像。在片段之间切换时,似乎图像不会从内存中清除。在片段之间切换几次后,我最终得到Out of Memory错误。

有关如何解决此问题的任何想法?

来自控制台的更多细节: E / dalvikvm-heap:1448188字节分配的内存不足。 I / dalvikvm:“uil-pool-2-thread-2”prio = 4 tid = 16 RUNNABLE

UIL配置:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                //.threadPriority(Thread.NORM_PRIORITY - 2)
                .threadPriority(Thread.MIN_PRIORITY + 3)
                .denyCacheImageMultipleSizesInMemory()
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .diskCacheSize(150 * 1024 * 1024) // 150 Mb
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .threadPoolSize(3)
                //.writeDebugLogs() // Remove for release app
                .build();
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);

UIL选项:

options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.section_load)
                .showImageForEmptyUri(R.drawable.section_load)
                .showImageOnFail(R.drawable.section_load)
                //.cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.EXACTLY)
                .cacheOnDisk(true)
                .build();

0 个答案:

没有答案