How Can You Identify and Prioritize Major Mono Memory Consumers in Unity?
When Mono memory repeatedly reaches 400–480MB and continues to increase during gameplay, how can you identify the main memory consumers and determine which data should be optimized first? https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/85b2e5e4 fc08 49b7 be18 339f4ace10d2.png
When Mono memory remains consistently high, looking at total memory usage alone is not enough. You need to distinguish between memory allocation and object retention, then use allocation call stacks and memory snapshots to identify the specific sources of memory consumption. According to the collected GameOptim GOT Online Mono mode report: During game startup, related memory allocations reach approximately 166MB. During subsequent multilingual configuration loading, related allocations reach approximately 60MB. Some configuration tables require nearly 30MB per load. Further inspection of memory snapshots also reveals that String, Dictionary.Entry, and large Int32 arrays account for significant memory usage. https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/5c8d80aa 415c 4ff0 8ddb a48c10f648be.png 1. Check the loading scope of configuration data According to the GameOptim GOT Online report, although multilingual configurations have already been split into separate tables, all language data is still merged and loaded at runtime. This means that even when only one language is currently in use, data for other languages may also occupy memory. For this situation, consider further separating configuration data by language and loading only the data required by the current language, rather than keeping all language data in memory. In addition, some configuration tables require nearly 30MB per load and contain numerous composite fields and List structures. Check whether any unnecessary data is being loaded or stored. https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/3002b620 bbab 4386 a29e 7a008832c8d3.png 2. Check the data structures of large arrays and collections In addition to configuration data, the memory snapshot module in the Mono mode report reveals multiple 1000×1000 Int32 map grid arrays, each occupying approximately 3.8MB. Based on the actual value range, evaluate whether Int32 can be replaced with Int16 or Byte to reduce storage requirements. If the application does not need to access the entire map simultaneously, consider chunking or on demand loading to avoid keeping the full dataset resident in memory for extended periods. https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/732aad25 13bf 43a9 b470 f4deeaa04fe5.png For collection structures such as Dictionary and List, check their specific usage to identify potential issues, including duplicated data storage, unreasonable capacity settings, or unused data being retained for extended periods. It is important to note that allocated memory is not the same as actual retained memory . For data with high allocation volumes, use memory snapshots to verify whether objects are still referenced and how much memory they actually occupy. Avoid diagnosing memory issues based solely on allocation call stacks. After optimization, compare Mono memory trends, major object types, and object retention changes under the same device and test procedure to verify whether the adjustments have actually reduced memory usage.