< Summary

Class:GDX.Memory
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Memory.cs
Covered lines:0
Uncovered lines:16
Coverable lines:16
Total lines:67
Line coverage:0% (0 of 16)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CleanUp()0%2100%
CleanUpAsync()0%20400%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Memory.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7using System.Threading.Tasks;
 8using UnityEngine;
 9
 10namespace GDX
 11{
 12    /// <summary>
 13    ///     A collection of memory related helper utilities.
 14    /// </summary>
 15    [VisualScriptingCompatible(8)]
 16    public static class Memory
 17    {
 18        /// <summary>
 19        ///     <para>Cleanup Memory</para>
 20        ///     <list type="bullet">
 21        ///         <item>
 22        ///             <description>Mono Heap (Garbage Collection)</description>
 23        ///         </item>
 24        ///         <item>
 25        ///             <description>Unity Resources (when not deployed on DOTS Runtime.</description>
 26        ///         </item>
 27        ///     </list>
 28        /// </summary>
 29        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30        public static void CleanUp()
 031        {
 32            // Fire off a first pass collection
 033            GC.Collect();
 34
 35            // Tell Unity to clean up any assets that it no longer wants to have loaded
 36#if !UNITY_DOTSRUNTIME
 037            Resources.UnloadUnusedAssets();
 38#endif
 39
 40            // Fire off second pass collection
 041            GC.WaitForPendingFinalizers();
 042            GC.Collect();
 043        }
 44
 45#if !UNITY_DOTSRUNTIME
 46        /// <inheritdoc cref="CleanUp" />
 47        /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 48        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 49        public static async void CleanUpAsync()
 050        {
 51            // Fire off a first pass collection
 052            GC.Collect();
 53
 54            // Tell Unity to clean up any assets that it no longer wants to have loaded
 055            AsyncOperation handle = Resources.UnloadUnusedAssets();
 056            while (!handle.isDone)
 057            {
 058                await Task.Delay(1000);
 059            }
 60
 61            // Fire off second pass collection
 062            GC.WaitForPendingFinalizers();
 063            GC.Collect();
 064        }
 65#endif
 66    }
 67}

Methods/Properties

CleanUp()
CleanUpAsync()