Search Issue Tracker
By Design
Votes
0
Found in
2022.3.61f1
6000.0.47f1
6000.1.0f1
6000.2.0a9
Issue ID
UUM-103862
Regression
No
UnsafeUtility.Malloc uses 4MB when creating an empty NativeQueue
How to reproduce:
1. Open the attached "IN-98674" project
2. Open the "test" scene
3. Navigate to the project directory and run the "test1.exe" (found in "IN-98674/Builds/test1")
4. In the "test1" window, press the Spacebar
5. Go to “Open Memory Profiler > Capture New Snapshot“
6. Select the captured snapshot
7. Navigate to “All of Memory > Native > Unity Subsystems > UnsafeUtility > Malloc (Persistent)”
8. Observe the “Allocated Size” value
Expected result: Malloc (Persistent) uses around 1.3-1.5KB of memory (similar to other native collections)
Actual result: Malloc (Persistent) uses 4.0MB of memory
Reproducible with: 2022.1.0a10, 2022.3.61f1, 6000.0.47f1, 6000.1.0f1, 6000.2.0a9
Could not test with: 2021.3.51f1 (different Memory Profiler UI made it difficult to locate the Malloc (Persistent) value)
Reproducible on: macOS 15.3 (M4), Windows 11 (by user)
Not reproducible on: No other environments tested
Notes:
- The “Test.cs“ script, attached to the “Main Camera” GameObject in the Hierarchy window, creates and deletes a NativeQueue when the Spacebar is pressed
- Reproducible with IL2CPP and Mono Scripting Backend
- The “GC Allocated In Frame” value in the Profiler window shows different results when creating a NativeQueue. With IL2CPP Scripting Backend, Windows shows 11.4 KB while MacOS shows 8.0 KB. With Mono Scripting Backend, Windows shows 2.2 KB while MacOS shows 2.5 KB
- a NativeQueue uses 4.0 MB of memory, while NativeList uses 1.3 KB, and NativeArray uses 1.5 KB
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
Resolution Note:
NativeQueue internally implements block caching mechanism that's used by all queues. The reason for memory bump is because on first use static method creates this pool of empty blocks, that are then used at later point.