Beispiel #1
0
        /// <summary>
        /// 内存阈值检测和自动对象回收
        /// </summary>
        void Update()                  //每帧删除
        {
            if (willGcList.Count == 0) //如果正在gc不需要判断
            {
                gcDeltaTime = Time.time - lastGcTime;
                if (gcDeltaTime >= gcDeltaTimeConfig)//20s检测一次
                {
                    float totalMemory = HugulaProfiler.GetTotalAllocatedMemory();
                    //Debug.Log(totalMemory);
                    if (totalMemory > threshold3)
                    {
                        AutoGC(gcSegment3);
                    }
                    else if (totalMemory > threshold2)
                    {
                        AutoGC(gcSegment2);
                    }
                    else if (totalMemory > threshold1)
                    {
                        AutoGC(gcSegment1);
                    }
                    else
                    {
                        gcSegmentQueue.Clear(); //不需要回收了
                    }
                }

                if (gcSegmentQueue.Count > 0) //队列有需要回收的片段
                {
                    byte segmentIndex = gcSegmentQueue.Dequeue();
                    GC(segmentIndex, false);
                }
            }



            if (willGcList.Count > 0) //如果有需要回收的gameobject
            {
                if (Time.deltaTime >= deltaTime30)
                {
                    removeCount = 5;
                }
                else if (Time.deltaTime >= deltaTime25)
                {
                    removeCount = 3;
                }
                else if (Time.deltaTime >= deltaTime20)
                {
                    removeCount = 2;
                }
                else if (Time.deltaTime >= deltaTime15)
                {
                    removeCount = 1;
                }

                DisposeRefer(removeCount);//移除数量
            }
        }
Beispiel #2
0
        /// <summary>
        /// 内存阈值检测和自动对象回收
        /// </summary>
        void LateUpdate()              //每帧删除
        {
            if (willGcList.Count == 0) //如果正在gc不需要判断
            {
                gcDeltaTime = Time.unscaledTime - lastGcTime;
                if (gcDeltaTime >= gcDeltaTimeConfig)//20s检测一次
                {
                    float totalMemory = HugulaProfiler.GetTotalAllocatedMemory();
                    //Debug.Log(totalMemory);
                    if (totalMemory > threshold3)
                    {
                        AutoGC(gcSegment3);
                    }
                    else if (totalMemory > threshold2)
                    {
                        AutoGC(gcSegment2);
                    }
                    else if (totalMemory > threshold1)
                    {
                        AutoGC(gcSegment1);
                    }

                    lastGcTime = Time.unscaledTime;
                }//
            }


            if (willGcList.Count > 0) //如果有需要回收的gameobject
            {
                var fps = Time.time / (float)Time.frameCount;
                if (fps >= deltaTime30)
                {
                    removeCount = 4;
                }
                else if (fps >= deltaTime25)
                {
                    removeCount = 3;
                }
                else if (fps >= deltaTime20)
                {
                    removeCount = 2;
                }
                else //if (fps >= deltaTime15)
                {
                    removeCount = 1;
                }

                DisposeRefer(removeCount);//移除数量
            }
        }