【问题标题】:Out Of Memory with pagerView MonodoridpagerView Monodorid 内存不足
【发布时间】:2013-04-30 14:09:53
【问题描述】:

我需要使用 pagerView。当我在一百页后使用 pagerview 时,应用程序给我错误“内存不足”。我需要一种方法来破坏视图,因为它让我一直都在记忆中(从头到尾)。 在视图中记住我制作的 4 个盒子,带有一个图像(不会改变)和两个按钮。

这是我的适配器:

namespace ProvaViewPager
{
    public class FragmentAdapter : FragmentStatePagerAdapter
    {
        int mCount;
        private FragmentManager mFragmentManager;

        public FragmentAdapter (FragmentManager fm) : base (fm)
        {
            mCount = 200;
            mFragmentManager = fm;
        }

        public override Fragment GetItem (int position)
        {
            return new SwiftView (position);
        }

        public override int Count {
            get {
                return mCount;  
            }   
        }

使用方法distroy?但是怎么做?

调试中的消息:

跳过了 55 帧!应用程序可能在其上做太多工作 主线程。将目标 GC 堆从 49.446MB 钳制到 48.000MB 钳制 目标 GC 堆从 49.847MB 到 48.000MB 将目标 GC 堆从 49.860MB 到 48.000MB 将目标 GC 堆从 49.859MB 固定到 48.000MB 强制收集 SoftReferences 以进行 712 字节分配钳制 目标 GC 堆从 49.859MB 到 48.000MB 712 字节内存不足 分配。将目标 GC 堆从 49.874MB 钳制到 48.000MB 钳制 目标 GC 堆从 49.874MB 到 48.000MB 强制收集 SoftReferences for 964-byte allocation Clamp target GC heap from 49.874MB 到 48.000MB 在 964 字节分配上内存不足。Mono.Debugging.Evaluation.EvaluatorException: Java.Lang.OutOfMemoryError:

在 Mono.Debugging.Soft.MethodCall.get_ReturnValue() 中

在 Mono.Debugging.Soft.SoftEvaluationContext.RuntimeInvoke(MethodMirror 方法、对象目标、Value[] 值)

在 Mono.Debugging.Soft.SoftDebuggerAdaptor.CallToString(EvaluationContext ctx, 对象 obj)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.TargetObjectToObject(EvaluationContext ctx, 对象 obj)

在 Mono.Debugging.Soft.SoftDebuggerAdaptor.TargetObjectToObject(EvaluationContext gctx, 对象 obj)

在 Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext ctx, 对象 obj)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValueImpl(EvaluationContext ctx、IObjectValueSource 源、ObjectPath 路径、Object obj、 ObjectValueFlags 标志)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValue(EvaluationContext ctx、IObjectValueSource 源、ObjectPath 路径、Object obj、 ObjectValueFlags flags) 将目标 GC 堆从 49.874MB 限制到 48.000MB 将目标 GC 堆从 49.874MB 限制到 48.000MB 强制收集 SoftReferences for 964-byte allocation Clamp target GC heap from 49.874MB 到 48.000MB 在 964 字节分配上内存不足。将目标 GC 堆从 49.874MB 钳制到 48.000MB

抱歉英语不好

【问题讨论】:

  • 您如何在 SwiftView 中准确地实例化您的 ImageView?您可能会将大量图像加载到内存中,这会使您的内存不足。请为 SwiftView 提供一些代码。

标签: xamarin.android out-of-memory viewpagerindicator


【解决方案1】:

然后创建一个包含一个box的ViewPager,由一个图像组成并写......每个页面由4个box组成。 这是我的创建框代码:

 namespace ProvaViewPager.Widget.CatalogoBox

{

    public class CatalogoBox : RelativeLayout

    {

        private LayoutInflater _mInflater;

        private LinearLayout _mBox;



        private void Initialize ()

        {

        }



        public CatalogoBox (IntPtr doNotUse, JniHandleOwnership transfer)

            : base(doNotUse, transfer)

        {

        }



        public CatalogoBox (Context context, IAttributeSet attrs)

            : base(context, attrs)

        {

            InternalCtor (context, attrs);

        }



        public CatalogoBox (Context context, IAttributeSet attrs, int defStyle)

            : base(context, attrs, defStyle)

        {

            InternalCtor (context, attrs);

        }



        ~CatalogoBox ()

        {

            Dispose (false);

        }





        private void InternalCtor (Context context, IAttributeSet attrs)

        {

            _mInflater = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);

            _mBox = (LinearLayout)_mInflater.Inflate (Resource.Layout.CatalogoBox, null);

            AddView (_mBox);

        }

    }

}

我们记得这里(SwiftView 类:Fragment):

public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

    {

        TextView TxtCDPAR;

        TextView TxtDEPAR;

        TextView TxtPrezzo;

        TextView TxtPz;



        ImageView ImageDisp;

        ImageView ImgFreccia;

        ImageView ImgIncrementa;

        ImageView ImgDecrementa;

        ImageView ImageItem;

        EditText Quantita;

        ImageView ImageProduct;

        LinearLayout BoxAddProdotto;

        View v = inflater.Inflate (Resource.Layout.PageViewXml, container, false);

        if (v != null) {

            #region BOX1

            var BoxProdotto1 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox1);

            TxtCDPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);

            TxtDEPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);

            ImageView ImagetItem1 = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;

            TxtPz = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);

            TxtPrezzo = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);

            BoxAddProdotto = BoxProdotto1.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);

            ImageDisp = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);

            ImgFreccia = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);

            ImgIncrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageIncrementa);

            ImgDecrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageDecrementa);

            Quantita = BoxProdotto1.FindViewById<EditText> (Resource.Id.editNumerico);

            ImageProduct = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);

            TxtPz.Visibility = ViewStates.Invisible;



            ImagetItem1.SetImageResource (Resource.Drawable.imagespiaggia);



            #endregion



            #region BOX2

            var BoxProdotto2 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox2);

            TxtCDPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);

            TxtDEPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);

            ImageItem = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;

            TxtPz = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);

            TxtPrezzo = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);

            BoxAddProdotto = BoxProdotto2.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);

            ImageDisp = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);

            ImgFreccia = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);

            ImgIncrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageIncrementa);

            ImgDecrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageDecrementa);

            Quantita = BoxProdotto2.FindViewById<EditText> (Resource.Id.editNumerico);

            ImageProduct = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);

            TxtPz.Visibility = ViewStates.Invisible;



            ImageItem.SetImageResource (Resource.Drawable.feliximage);



            #endregion

这是适配器:

namespace ProvaViewPager

{

public class FragmentAdapter : FragmentStatePagerAdapter

{

    int mCount;

    private FragmentManager mFragmentManager;



    public FragmentAdapter (FragmentManager fm) : base (fm)

    {

        mCount = 200;

        mFragmentManager = fm;

    }



    public override Fragment GetItem (int position)

    {

        return new SwiftView (position);

    }



    public override int Count {

        get {

            return mCount;  

        }   

    }



    public override Java.Lang.Object InstantiateItem (ViewGroup container, int position)

    {
        return base.InstantiateItem (container, position);

    }



    public override void DestroyItem (ViewGroup collection, int position, Java.Lang.Object view)

    {

        base.DestroyItem(collection,position,view);



    }

}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-15
    • 2011-05-21
    • 2021-12-20
    • 2021-10-29
    • 1970-01-01
    • 2020-03-12
    • 2015-08-11
    • 2019-06-07
    相关资源
    最近更新 更多