android 通用图像加载器内存不足
android universal image loader out of memory
我正在加载大约 50 张图片。在我的 activity 我有这个配置
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisk(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.resetViewBeforeLoading(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.diskCacheSize(100 * 1024 * 1024)
.build();
ImageLoader.getInstance().init(config);
在活页夹数据中
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(uri, holder.iv_img);
有些图像已加载,但有些未加载,我收到 OutOfMemory
错误。
查看来自 Useful Info
的提示
If you often got OutOfMemoryError in your app using Universal Image
Loader then:
- Disable caching in memory. If OOM is still occurs then it seems your app has a memory leak. Use MemoryAnalyzer to detect it. Otherwise
try the following steps (all of them or several):
- Reduce thread pool size in configuration (.threadPoolSize(...)). 1 - 5 is recommended.
- Use .bitmapConfig(Bitmap.Config.RGB_565) in display options. Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
Use .imageScaleType(ImageScaleType.EXACTLY) (Your already use this tips)
- Use .diskCacheExtraOptions(480, 320, null) in configuration
希望对您有所帮助!!
1.I 建议您查看 Facebook 的 图片管理库 与其他图片加载库相比,Fresco 非常棒且成熟.
2.Fresco 使用 3 层架构(BITMAP_MEMORY_CACHE
、ENCODED_MEMORY_CACHE
和 DISK_CACHE
)处理所有图像缓存。 它还减少了 OOM(内存不足)问题。当视图中的图像超出屏幕时,它会自动回收位图,从而释放内存。
3.Fresco 具有 SimpleDraweeView
作为自定义图像视图,它支持圆角和圆形 link 并支持动画(.gif
、.webp
)以及普通图片(.jpg
, .png
).
我正在加载大约 50 张图片。在我的 activity 我有这个配置
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisk(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.resetViewBeforeLoading(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.diskCacheSize(100 * 1024 * 1024)
.build();
ImageLoader.getInstance().init(config);
在活页夹数据中
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(uri, holder.iv_img);
有些图像已加载,但有些未加载,我收到 OutOfMemory
错误。
查看来自 Useful Info
的提示If you often got OutOfMemoryError in your app using Universal Image Loader then:
- Disable caching in memory. If OOM is still occurs then it seems your app has a memory leak. Use MemoryAnalyzer to detect it. Otherwise try the following steps (all of them or several):
- Reduce thread pool size in configuration (.threadPoolSize(...)). 1 - 5 is recommended.
- Use .bitmapConfig(Bitmap.Config.RGB_565) in display options. Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
Use .imageScaleType(ImageScaleType.EXACTLY)(Your already use this tips)- Use .diskCacheExtraOptions(480, 320, null) in configuration
希望对您有所帮助!!
1.I 建议您查看 Facebook 的 图片管理库 与其他图片加载库相比,Fresco 非常棒且成熟.
2.Fresco 使用 3 层架构(BITMAP_MEMORY_CACHE
、ENCODED_MEMORY_CACHE
和 DISK_CACHE
)处理所有图像缓存。 它还减少了 OOM(内存不足)问题。当视图中的图像超出屏幕时,它会自动回收位图,从而释放内存。
3.Fresco 具有 SimpleDraweeView
作为自定义图像视图,它支持圆角和圆形 link 并支持动画(.gif
、.webp
)以及普通图片(.jpg
, .png
).