内存与pagerView Monodorid

时间:2013-04-30 14:09:54

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

我需要一个关于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 Clamp   目标GC堆从49.847MB到48.000MB Clamp目标GC堆   49.860MB到48.000MB Clamp目标GC堆从49.859MB到48.000MB强制收集SoftReferences用于712字节分配钳位   目标GC堆从49.859MB到48.000MB 712字节的内存不足   分配。钳制目标GC堆从49.874MB到48.000MB Clamp   目标GC堆从49.874MB到48.000MB强制收集   用于964字节分配的SoftReferences从中捕获目标GC堆   49.874MB到48.000MB 964字节分配内存不足.Mono.Debugging.Evaluation.EvaluatorException:   Java.Lang.OutOfMemoryError:

     Mono.Debugging.Soft.MethodCall.get_ReturnValue()

中的

     

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

     

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

     

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

     

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

     

在   Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext   ctx,Object 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强制收集   用于964字节分配的SoftReferences从中捕获目标GC堆   49.874MB到48.000MB 964字节分配的内存不足。钳制目标GC堆从49.874MB到48.000MB

抱歉英文不好

1 个答案:

答案 0 :(得分:0)

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

 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);



    }

}

}