Where Are You Wasting Your Game's Memory? (Memory Profiler: Part 2)

July 2, 2020
protect

Today, I will show you around the neat memory map visualization mode that this experimental package brings to your table:

  • How is your memory layout structured?

  • What memory regions does Unity have?

  • How fragmented is your memory?

This is the second post on the Unity Memory Profiler series. In the first post, I showed you what the memory profiler is and how it can help you visualize where you are spending your memory on.

Today, I'll show you around the memory map visualization mode.

Basic

Table of Contents

1 What is Your Game's Memory Map?

2 Capturing Your Game's Memory Map

3 What's In Your Memory Blocks?

3.1 The Regions List

3.2 The Allocations List

3.3 The Objects List.

4 What's Next?

What is Your Game's Memory Map?

The memory map is all about how Unity structures your game's content in RAM. That includes the engine content as well.

Now, your game might have GBytes of assets, but only a portion of that is placed into RAM.

memory-map-memory-profiler

Memory Map Profiler (Source: Unity)

Your memory map not only includes "content" *in the traditional sense of assets). It also includes our variables and other important data structures that we need for our gameplay systems.

Some examples:

  • Variables in the heap

  • Networking data structures

  • Player stats

  • Intermediate buffers of all sorts

  • Memory pools, etc..

If you haven't heard of that yet, that's okay.

Your memory structure is something that Unity hides from you for an excellent reason: Unity game developers rarely need to be concerned about this.

However, there are a couple of cases where analyzing your memory layout can be useful, such as

  • Fine-tuning your memory usage

  • Developing cache-friendly systems such as DOTS

  • Diagnosing and fixing problems related to memory fragmentation

In Unity, the chances that you need to go so deep into this topic are low, quite frankly. Some of these features are mostly for engine developers.

But you know what?

Learning about memory maps in game development is just exciting.

You get to know areas that almost no Unity game developer knows about.

Guess what happens when you talk about this in a job interview, or just in front of your #gamedev colleagues?

Let's see how to access your Unity game memory map.

Capturing Your Game's Memory Map

You can easily capture a memory snapshot of your game and open it for analysis, just like I detailed in part 1.

Ideally, you will want to do this in a development player build. Otherwise, you'll see a lot of noise coming from the unity editor (this is specially true when profiling memory).

On the top side of the memory profiler, you can switch from the default Unity Tree Map visualization mode to Memory Map.

Unity Memory Profiler: Switching to Memory Map

Unity-Memory-Profiler-Memory-Map-Mode

Unity Memory Profiler: Switching to Memory Map

After switching to the memory map, you'll see something like this:

Unity Memory Profiler: Memory Map (Overview)

Unity-Memory-Profiler-Memory-Map-Overview

Unity Memory Profiler: Memory Map (Overview)

What the heck does this all mean?

As you can see, this displays how Unity lies out your memory in a linear, top-down fashion.

And these memory blocks you see have different colors according to the legend above:

  • Managed memory and managed objects: blue

  • Native memory (reserved/allocated): green

Let's get an overview.

  1. Virtual Address.
    This is the current location (virtual address) of that memory area

  2. Memory Blocks.
    These are the blocks or "buckets" that Unity defines in that memory area. Each memory bucket has a memory specific storage function for your game.

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Read More>>