Exemplo n.º 1
0
        private void GarbageCheckLoop()
        {
            try {
                for (; ;)
                {
                    GC.RegisterForFullGCNotification(10, 10);
                    GC.WaitForFullGCApproach();
                    if (Garbage.ManualCollection)
                    {
                        continue;
                    }
                    lock (CollectLock) {
                        while (DrawState.TriggerGC)
                        {
                            Thread.Sleep(32);
                        }

                        MTexture2D.PurgeDataCache();
                        DrawState.TriggerGC = true;
                        // TODO : Do other cleanup attempts here.
                    }
                }
            }
            catch {
            }
        }
Exemplo n.º 2
0
        private void MemoryPressureLoop()
        {
            if (Runtime.Framework != Runtime.FrameworkType.DotNET)
            {
                return;
            }

            for (;;)
            {
                if (DrawState.TriggerGC)
                {
                    Thread.Sleep(128);
                    continue;
                }

                lock (CollectLock) {
                    try {
                        using var _ = new MemoryFailPoint(Config.RequiredFreeMemory);
                        Thread.Sleep(128);
                    }
                    catch (InsufficientMemoryException) {
                        Debug.WarningLn($"Less than {(Config.RequiredFreeMemory * 1024 * 1024).AsDataSize(decimals: 0)} available for block allocation, forcing full garbage collection");
                        MTexture2D.PurgeDataCache();
                        DrawState.TriggerGC = true;
                        Thread.Sleep(10000);
                    }
                }
            }
        }