Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何处理毕加索OutOfMemoryError?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想显示一个约50页的ViewPager,每页包含不同的图像.使用毕加索,前20-25页的工作完美.然而,在这一点上,我得到一个OutOfMemoryError,并且根本没有加载图像:
Throwing OutOfMemoryError "Failed to allocate a 7477932 byte alLOCATIOn with 1932496 free bytes"
@H_607_4@我在PagerAdapter中使用以下代码

@Override
public Object instantiateItem(final ViewGroup container,final int position) {
    View view = getView();
    PiCasso piCasso = getImageLoader(mContext);
    piCasso.load(getUrl(position)).fit().into((ImageView) view.findViewById(R.id.imageview));
    container.addView(view);
    return view;
}

@Override
public void destroyItem(final ViewGroup container,final int position,final Object object) {
    container.removeView((View) object);
}
@H_607_4@我可以做些什么来避免这种情况?

解决方法

我找到了 this issue. @H_607_4@有几点指出:

@H_607_4@>使用skipMemoryCache()
>使用builder.executor(Executors.newSingleThreadExecutor());
>使用毕加索的一个例:不要每次使用毕加索.builder创建一个新的实例.

@H_607_4@我设法解决了我最后一个问题.

大佬总结

以上是大佬教程为你收集整理的android – 如何处理毕加索OutOfMemoryError?全部内容,希望文章能够帮你解决android – 如何处理毕加索OutOfMemoryError?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。