Search Issue Tracker
By Design
Votes
0
Found in
2017.4.0f1
2017.4.6f1
Issue ID
1126514
Regression
No
GC.Collect occasionally fails to clean everything, resulting in Memory leakage on Players and in Editor
When Memory is allocated, the total Memory value is printed and that Memory is freed and cleaned with "GC.Collect". However, occasionally, the GC will fail to clean up the freed Memory, resulting in a Memory Leak.
To reproduce:
1. Download attached project “MemoryLeak.zip" and open in Unity
2. Open "MemoryLeak" scene
3. Enter to Play mode
4. Print "Activate Incremental Memory Loop" button in Game window
5. Look towards the Console, there can be 2 printouts:
1. Log 'Loop # Memory Before: # After GC: #' - This means no memory leak has occurred this frame
2. Warning 'Loop # Memory Before: # After GC: # Memory loss: #' - This means memory has either leaked or regained. If the number is positive, then a memory leak has occurred
Expected results: GC.Collect would clean up all freed Memory
Actual results: Sometimes GC.Collect fails to clean Memory and a Leak occurs
Notes:
- This issue appears on Windows Standalone, macOS Standalone, iOS, and Android
- This issue also appears on Editor
- I attached Profiler results which show Memory Leak in Editor and Standalone (Mono)
Reproduced on Unity 2017.4.0f1, 2017.4.20f2, 2018.3.6f1, 2019.1.0b3 and 2019.2.0a6
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
- Too little validation messages in the "WebAssembly Language Features" Memory settings
- Project Settings Search Highlights are misaligned when using the Bitmap Text Rendering Mode
- "GetControlID at event ValidateCommand returns a controlID different from the one in Layout event" Warning is thrown when undoing the deletion of Sprite Shape Profile
- Memory related fields in the "WebAssembly Language Features" can be set to the negative numbers
- "WebAssembly Language Features" Header in the Player Settings has a smaller indentation
Resolution Note:
The test script allocates larger and larger managed arrays. These larger and larger sizes require new blocks to be allocated from OS for GC to fulfill. Eventually the available memory for the process will be exhausted.