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

Mono

-

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

  1. 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.

  2. 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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.