Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
2
Found in
2021.3.16f1
2022.2.2f1
2023.1.0a25
Issue ID
UUM-23303
Regression
No
Fragmentation on a managed object when using Finalizer
Reproduction steps:
1. Open the attached project "ReproProject"
2. Build and run the project (File > Build and Run)
3. Open Window > Analytics > Memory Profiler
4. Take a capture
5. Go to {{\Package\Runtime\RuntimeValues.cs}}
6. Uncomment the commented lines (finalizer)
7. Repeat 2, 3, and 4 steps
8. Compare both captures
9. Take a look at the difference of “Empty Fragmented Heap Space”
Expected result: The “Empty Fragmented Heap Space” difference is little or non
Actual result: The “Empty Fragmented Heap Space” noticeably differs between captures
Reproducible with: 2021.3.16f1, 2022.2.2f1, 2023.1.0a25
Could not test with: 2020.3.42f1 (Library\PackageCache\com.unity.memoryprofiler@1.0.0\Editor\Containers\MetaDataHelpers.cs(70,82): error CS8124: Tuple must contain at least two elements)
Reproducible on: Windows 10 Enterprise 21H2
Notes:
- Reproducible on Android
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
- Economy package throws a CS0619 error in the Console when installed together with Deployment package
- “Screen position out of view frustum” errors are thrown when zooming out in the Scene view with Rect Tool selected
- Only one [UnityOneTimeSetUp] method runs when there are 2 of them in different classes
- Crash with multiple stack traces when Sprites with a high resolution get Sliced to a Grid with a small cell size in the Sprite Editor
- The UI Builder's Data Source Object picker cannot be navigated after triggering a circular dependency dialog box
Resolution Note:
The GC Unity currently uses is not a moving GC, so fragmentation is possible. Types with finalizers can cause additional fragmentation, as those objects must live a bit longer - waiting for their finalizers to be run.
So unfortunately this is expected behavior. As we move to use the CoreCLR runtime, Unity will use a moving GC which will handle heap fragmentation much more effectively.
Resolution Note (2023.1.X):
The GC Unity currently uses is not a moving GC, so fragmentation is possible. Types with finalizers can cause additional fragmentation, as those objects must live a bit longer - waiting for their finalizers to be run.
So unfortunately this is expected behavior. As we move to use the CoreCLR runtime, Unity will use a moving GC which will handle heap fragmentation much more effectively.