-
Notifications
You must be signed in to change notification settings - Fork 14
Memory Budgeting & Resource Unloading
Vitaly Popuzin edited this page Dec 8, 2023
·
6 revisions
Memory budgeting in Unity is essential for maintaining system stability and preventing memory overflow and crashes by keeping memory usage within set limits. It ensures smooth application performance across various platforms with different hardware capacities. This approach also aids in efficient resource management, allowing for strategic asset loading and unloading decisions.
In the project there are several components related to it:
-
IProfilingProviderprovides information about current memory usage by reading it from respective Unity built-inProfilerRecorder -
ISystemMemoryprovides information about total available system memory. Polymorphism should be used to access data on different devices. -
MemoryBudgetProvideris core component of the memory budgeting system. It implementsIConcurrentBudgetProviderand uses data fromIProfilingProviderto understand its relation to the total system memory fromISystemMemoryand relates it to the respective threshold. It will return false forTrySpendBudget()call if the memory usage is in the Full threshold (defined by settings as a certain percentage of total system memory).
Similarly to other budget providers, this MemoryBudgetProvider then is used by different systems that are potentially can lead to memory consumption. Such systems prevent loading flow when the budget cannot be spend. Examples could be found in CreateGltfAssetFromAssetBundleSystem and DeferredLoadingSystem.
---
title: Memory Budgeting for Loading
---
classDiagram
class ClientSystem["System that utilize memory budget"]
class IConcurrentBudgetProvider {+TrySpendBudget() bool }
ClientSystem --> IConcurrentBudgetProvider : Uses TrySpendBudget() in its own loading logic
direction LR
IConcurrentBudgetProvider <|-- MemoryBudgetProvider : implements
MemoryBudgetProvider --> IProfilingProvider : get currently used memory
MemoryBudgetProvider --> ISystemMomery : get total available memory