通用图像装载机UIL诺斯特拉内存不足的错误 [英] Universal Image Loader UIL nostra out of memory error

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

问题描述

我使用UIL加载远程图像和FragmentStatePagerAdapter填补碎片。
我已阅读自述和往常一样的错误,但我不能彻底解决掉这个bug。

I am using UIL to load remote images and fill up Fragments in FragmentStatePagerAdapter. I have read readme and usual errors but I can't solve out this bug.

下面是配置:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    .threadPoolSize(1)
    .build();
    ImageLoader.getInstance().init(config);

下面是我显示我的图片:

Here is where i display my images:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {


    ImageLoader imgLoader = ImageLoader.getInstance();

    DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.loading)
    .cacheOnDisc()
    .resetViewBeforeLoading()
    .bitmapConfig(Bitmap.Config.RGB_565)
    .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
    .build();

    imgLoader.displayImage(this.contentImage, this.imgView, options);

    return layout;
}

和这里是我毁了我的片段适配器:

And here is where I destroy my fragments in the adapter:

public void destroyItem(ViewGroup container, int position, Object object) {
    if (position >= getCount()) {
        container.removeAllViews();
        FragmentManager manager = ((Fragment) object).getFragmentManager();
        FragmentTransaction trans = manager.beginTransaction();
        trans.remove((Fragment) object);
        trans.commit();
    }
}

和终于在这里是例外,我得到:

and finally here is the exception I get:

{
06-20 12:09:24.877: E/dalvikvm-heap(17043): Out of memory on a 6345504-byte allocation.
06-20 12:09:24.877: I/dalvikvm(17043): "pool-1-thread-1" prio=4 tid=16 RUNNABLE
06-20 12:09:24.877: I/dalvikvm(17043):   | group="main" sCount=0 dsCount=0 obj=0x42593a48 self=0x6367e778
06-20 12:09:24.887: I/dalvikvm(17043):   | sysTid=17091 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1667639656
06-20 12:09:24.887: I/dalvikvm(17043):   | state=R schedstat=( 4021618000 2254117000 18267 ) utm=341 stm=61 core=0
06-20 12:09:24.887: I/dalvikvm(17043):   #00  pc 00074350  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
06-20 12:09:24.887: I/dalvikvm(17043):   #01  pc 00062afe  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+557)
06-20 12:09:24.887: I/dalvikvm(17043):   #02  pc 00062bae  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
06-20 12:09:24.887: I/dalvikvm(17043):   #03  pc 000298ec  /system/lib/libdvm.so (dvmMalloc(unsigned int, int)+584)
06-20 12:09:24.887: I/dalvikvm(17043):   #04  pc 0007fdfe  /system/lib/libdvm.so (dvmAllocPrimitiveArray(char, unsigned int, int)+93)
06-20 12:09:24.887: I/dalvikvm(17043):   #05  pc 0005357e  /system/lib/libdvm.so
06-20 12:09:24.887: I/dalvikvm(17043):   #06  pc 000798e0  /system/lib/libandroid_runtime.so (GraphicsJNI::allocateJavaPixelRef(_JNIEnv*, SkBitmap*, SkColorTable*)+67)
06-20 12:09:24.887: I/dalvikvm(17043):   #07  pc 000799ae  /system/lib/libandroid_runtime.so (JavaPixelAllocator::allocPixelRef(SkBitmap*, SkColorTable*)+45)
06-20 12:09:24.887: I/dalvikvm(17043):   #08  pc 0004aa18  /system/lib/libskia.so (SkBitmap::allocPixels(SkBitmap::Allocator*, SkColorTable*)+56)
06-20 12:09:24.887: I/dalvikvm(17043):   #09  pc 000cd848  /system/lib/libskia.so (SkPNGImageDecoder::onDecode(SkStream*, SkBitmap*, SkImageDecoder::Mode)+404)
06-20 12:09:24.887: I/dalvikvm(17043):   #10  pc 000c9504  /system/lib/libskia.so (SkImageDecoder::decode(SkStream*, SkBitmap*, SkBitmap::Config, SkImageDecoder::Mode, bool)+168)
06-20 12:09:24.887: I/dalvikvm(17043):   #11  pc 00075a08  /system/lib/libandroid_runtime.so
06-20 12:09:24.887: I/dalvikvm(17043):   #12  pc 000762ac  /system/lib/libandroid_runtime.so
06-20 12:09:24.887: I/dalvikvm(17043):   #13  pc 0001dd8c  /system/lib/libdvm.so (dvmPlatformInvoke+112)
06-20 12:09:24.887: I/dalvikvm(17043):   #14  pc 0005a6e2  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+165)
06-20 12:09:24.887: I/dalvikvm(17043):   #15  pc 000271a0  /system/lib/libdvm.so
06-20 12:09:24.887: I/dalvikvm(17043):   #16  pc 0002b898  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
06-20 12:09:24.887: I/dalvikvm(17043):   #17  pc 00073d2c  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+563)
06-20 12:09:24.887: I/dalvikvm(17043):   #18  pc 00073e04  /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+19)
06-20 12:09:24.887: I/dalvikvm(17043):   #19  pc 000640f4  /system/lib/libdvm.so
06-20 12:09:24.887: I/dalvikvm(17043):   #20  pc 0000dcfc  /system/lib/libc.so (__thread_entry+124)
06-20 12:09:24.887: I/dalvikvm(17043):   #21  pc 0000d8d0  /system/lib/libc.so (pthread_create+172)
06-20 12:09:24.887: I/dalvikvm(17043):   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
06-20 12:09:24.887: I/dalvikvm(17043):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
06-20 12:09:24.887: I/dalvikvm(17043):   at com.nostra13.universalimageloader.core.ImageDecoder.decode(ImageDecoder.java:82)
06-20 12:09:24.887: I/dalvikvm(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:270)
06-20 12:09:24.887: I/dalvikvm(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:244)
06-20 12:09:24.887: I/dalvikvm(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:149)
06-20 12:09:24.887: I/dalvikvm(17043):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-20 12:09:24.887: I/dalvikvm(17043):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-20 12:09:24.887: I/dalvikvm(17043):   at java.lang.Thread.run(Thread.java:856)
06-20 12:09:24.897: D/skia(17043): --- decoder->decode returned false
06-20 12:09:24.897: E/ImageLoader(17043): null
06-20 12:09:24.897: E/ImageLoader(17043): java.lang.OutOfMemoryError
06-20 12:09:24.897: E/ImageLoader(17043):   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
06-20 12:09:24.897: E/ImageLoader(17043):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
06-20 12:09:24.897: E/ImageLoader(17043):   at com.nostra13.universalimageloader.core.ImageDecoder.decode(ImageDecoder.java:82)
06-20 12:09:24.897: E/ImageLoader(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:270)
06-20 12:09:24.897: E/ImageLoader(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:244)
06-20 12:09:24.897: E/ImageLoader(17043):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:149)
06-20 12:09:24.897: E/ImageLoader(17043):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-20 12:09:24.897: E/ImageLoader(17043):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-20 12:09:24.897: E/ImageLoader(17043):   at java.lang.Thread.run(Thread.java:856)
}

我没有在如何解决这个问题的任何想法。
加载的图像的大小可变。他们可能会有所不同,从500KB到1.5MB。

I don't have any idea in how to solve it. Loaded images are variable in size. They may vary from 500KB to 1.5MB.

推荐答案

解决:

据wasnt't一个UIL问题。问题是与页面适配器。在片段的位图不是由GC正确处理及有一些间接引用保留它们。释放位图明确地解决了这个问题。

It wasnt't a UIL problem. The problem was with the page adapter. The bitmaps in the Fragments weren't handled properly by the GC and there was some indirect reference retaining them. Freeing the bitmaps explicitely solved the problem.

编辑:

这不是一个正确的UIL问题。我与SupportFragment图书馆工作,而这可能无法正确​​调整。对我来说,技巧是手动释放每一个位图,它是不是在屏幕上,但问题应该以不同的方式来看待。此应用程序使用一个非常大的网页视图中,在我看来是邪恶的,由于事实,即他们的内存消耗简直是傻了!与高分辨率图像添加UIL让我的应用程序会OOM由于这些因素的组合。

It wasn't a proper UIL problem. I was working with SupportFragment library, and this may be not properly tweaked. The trick for me was manually release every bitmap that was not on screen, but the problem should be looked at in a different way. This application uses a very large amount of WebViews, that in my opinion are evil due to fact that their memory consumption is simply silly! Adding UIL with hi-res images makes my app going OOM due to the combination of these factors.

这是一个有点经验的解决方案,但它确实有效。

It's a bit empirical solution, but it really works.

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

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