Search Issue Tracker
Won't Fix
Votes
0
Found in [Package]
1.1.0-pre.3
Issue ID
PROFB-184
Regression
No
Memory leak when interacting with the Memory Profiler while a Snapshot is opened
Reproduction steps:
1. Open the "IN-56609.zip" project
2. Open "Scenes/SampleScene"
3. Open the Profiler (Window -> Analysis -> Profiler)
4. Click on the "Play mode" dropdown menu and select "Edit Mode" in the Profiler window
5. Click on the "Memory" module in the Profiler window
6. Open the Memory Profiler (Window -> Analysis -> Memory Profiler)
7. Enter Play mode
8. Click on "Capture" in the Memory Profiler window and open the captured Snapshot
9. Observe the Managed Memory amount in the Profiler window
Expected results: No changes in Managed Memory allocation
Actual results: Managed Memory allocation is increased by 2 or 3 times
Reproducible with: 0.7.1-preview.1 (2021.3.31f1), 1.0.0 (2022.3.10f1), 1.1.0-pre.3 (2022.3.10f1, 2023.1.16f1, 2023.2.0b13, 2023.3.0a9)
Reproducible on: macOS 14.0 (M1)
Not reproducible on: No other environment tested
Notes:
- Switching between the "Summary", "Unity Objects" and "All Of Memory" tabs in the Memory Profiler window may further increase Managed Memory allocation
- In some Unity Editor or Memory Profiler versions, the Native Memory allocation increases instead of the Managed Memory allocation
Developer Remarks:
- Some increase in memory usage by the Editor when that Editor has a Memory Profiler in it that is opening a memory snapshot and displaying its details is to be expected. After all:
-- The snapshot has to be loaded into memory for processing. This includes the entire managed heap which is saved into the snapshot byte by byte.
--- In 1.0.0 the memory Profiler loads the Managed Heap into memory as managed "{{{}byte[]{}}}" data, one array per contiguous managed heap section. In 1.1.x it loads it into UnsafeUtility.Malloc(Persistent) memory, and might split contiguous managed heap sections into allocations smaller than int.MaxValue Bytes. (Version 1.0 would just completely fail to load snapshots with contiguous heap sections bigger than int.MaxValue Bytes.) This change reduces the amount of _managed_ memory used for just opening a snapshot, as well as the effect this has on expanding the Managed Heap and afterwards possibly retained Reserved amounts, as well as negative impacts on Fragmentation of the Managed Heap. But that same memory amount is now just loaded into Native Memory, meaning the total memory usage is unaffected between versions.
- In Unity versions from 2022.2.0a9 up to (and excluding) 2022.3.10f1, there were Memory Leaks in the Editor's native Text solution that affected, among other possible places in the Editor, the Memory Profiler package's override to the Profiler Window's Memory Usage Module, causing it to continuously leak native Mesh objects (Detailed in: [UUM-35117|https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-35117], [UUM-44477|https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-44477] and [UUM-46520|https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-46520]). Additionally, the same Module override was leaking managed memory between versions 1.1.0-exp.1 and 1.1.0-pre.3 of the package ([PROFB-160|https://issuetracker.unity3d.com/product/unity/issues/guid/PROFB-160]). These leaks might contribute to the assumption that the Memory Profiler is handling memory wrongly, and they might have convoluted test data during the initial analysis of this issue ticket.
- This repro requires the Profiler Window to keep recording more frame data, including for the frames in which the Editor opened the snapshot and created the UI to display the contents of the snapshot. Investigating this repro with detailed snapshot comparison analysis and the All Of Memory page of the Memory Profiler revealed that:
-- Some memory was held in 1.0 due to how the package initializes Quick Search for it's Find In Editor and Select In Editor functionality. This logic has been changed for 1.1 and seems to no longer be causing any issues
-- The majority of the snapshot data does indeed end up in Native > Unity Subsystems > Unsafe Utility > Malloc(Persistent), as expected and explained above
-- Other increases in Native Memory come from the Additional Frame Data listed under Native > Unity Subsystems > Profiling > ProfilerSession / Timeline View and some memory held for TimelineView Meshes. All in the range of the expected.
-- Some asset file icons are loaded for UI purposes
-- There's an about 2.7MB increase in Managed Objects memory usage, which seems reasonable for the amount of UI and data structures needed to display the snapshot contents.
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
- GPU utilization increases by 20% on Meta Quest headsets when Render Graph is enabled on 6000.0.16f1 and higher
- Value on Slider (Int) control in UI Builder displays as default when saving UI Document
- Color mismatch in UI Builders Library panel when the Editors theme is set to Light Mode
- [Android ] "AndroidJNI.ToBooleanArray" returns a random non-zero value instead of "IntPtr.Zero" when the method argument is null
- Non-HDR color picker opens when selecting material color with HDR enabled
Resolution Note:
See Developer Notes in the issue. Quick summary is that behaviour is improved in Memory Profiler 1.1.0 and this should be used where possible.
That said some memory use by the memory profiler is expected.