There are two ways of analyzing memory usage in your application in Unity:
This page covers information on the built-in Memory Profiler module. For more information on the Memory profiler package, see the Memory Profiler documentation.
The Memory Profiler module visualizes counters that represent the total allocated memory in your application. You can use the memory module to see information like the number of loaded objects, and the memory that they take in total per category. You can also see the number of GC allocations per Profiler frame.
When you profile your application in the Editor, the information in the Memory module indicates the memory usage in the Editor. These numbers are generally larger than when running on the release platform, because running the Unity Editor uses specific objects that take up memory, and the Editor window itself uses extra memory. Additionally, the Profiler displays memory that it uses, because Unity cannot cleanly separate it from the memory that the Play mode Player uses.
For more precise numbers and memory usage for your application, connect the Profiler to the running player via the Attach to Player menu. This allows you to see the actual usage on the target device.
The Memory module is divided into six charts that display detailed information on where your application spends memory. You can change the order of the categories in the chart; to do this, drag and drop them in the chart’s legend. You can also click a category’s colored legend to toggle its display.
Category | Description |
---|---|
Total Allocated | The total memory your application has used |
Texture Memory | How much memory the Textures in your application have used |
Mesh Memory | How much memory the Meshes in your application have used |
Material Count | The number of Material instances in your application |
Object Count | The number of native object instances in your application |
Total GC Allocated | The amount of memory used by the GC heap |
GC Allocated | The amount of memory allocated per frame on the GC heap |
There are two views available in the module details pane, located at the bottom of the Profiler window: Simple and Detailed. To change the view, select it from the dropdown in the top left of the module details pane.
The Simple view displays an overview of how memory is used throughout Unity in real-time on a per-frame basis.
Unity reserves memory pools for allocations to avoid asking the operating system for memory too often. This is displayed as a reserved amount, and how much it uses.
Выводится для следующих областей:
The values in the Profiler are different to those displayed in your operating system’s task manager, because the Memory Profiler does not track all memory usage in your system. This includes memory some drivers and plug-ins use, and memory used for executable code. On platforms that support getting the total memory size of the application from the operating system, the Total System Memory Usage is over 0 and is the same size in a task manager.
The Profiler also lists memory statistics for some of the most common Asset and GameObject types. These statistics include the count (before the forward slash) and the used memory. In this list, the Total Object Count displays the total number of native GameObjects that your application creates. If this number rises over time, your application is creating GameObjects and never destroying them.
You can use the Detailed view to take a snapshot of your application’s current state. Click the Take Sample button to capture detailed memory usage for the current target. It takes the Profiler a lot of time to get this data, so the Detailed view does not give you real-time details. After the Profiler takes a sample, the Profiler window displays a tree view where you can explore your application’s memory usage in more detail.
Enable the Gather object references setting at the top of the module details pane to collect information about what might be referencing an object at the time of the snapshot. This information is displayed in the right-hand pane of the window.
The objects that use memory are divided into the following categories in the tree view:
When you click on an object in the Assets or Scene Memory list, it’s highlighted in the Project or Scene view.
Note: In the Other category, memory reported under System.ExecutableAndDlls is read-only memory. The operating system might discard these pages as needed and later reload them from the file system. This generates lower memory usage, and usually does not directly contribute to the operating system’s decision to close your application if it uses too much memory. Some of these pages might also be shared with other applications that are using the same frameworks.