Search Issue Tracker
By Design
Votes
7
Found in
2017.3.0f3
Issue ID
1006637
Regression
No
References to assets are not unloaded from memory and garbage collected after destroying MonoBehaviour
Steps to reproduce:
1. Open attached “GarbageCollectionBugs.zip” Unity project
2. Open “Example” scene
3. Enter Play mode
4. Open Window->Profiler
5. Make sure that Memory Profiler is added and Detailed mode is enabled in Profiler
6. Click "Take Sample: Editor" in Profiler
-Notice the sprite references under Assets->Sprite in Profiler
7. Click on “DESTROY REFERENCE HOLDER” in Game view
8. Click "Take Sample: Editor" in Profiler
-Notice a sprite reference under Assets->Sprite in Profiler remains
Expected results:
References in destroyed objects are unloaded and garbage collected
Actual results:
After destroying MonoBehaviour, referenced assets are not unloaded and remain in memory
Reproduced in: 2018.2.0a2, 2018.1.0b9, 2017.3.1p2, 2017.2.2f1, 2017.1.3p2, 2017.1.0a1
Workaround: Set object to null in OnDestroy()
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:
We are closing this issue as by design. The issue will be addressed as a feature.
We will notify developer that there are manages reference that are not nullified after Destroy is called. This will be an optional Profiler feature for the Editor/Development Player with no performance overhead in Release. Combined with new MemoryProfiler it should make the discovery of zombie objects much easier.
See more details at https://forum.unity.com/threads/editor-is-taking-20-seconds-to-enter-playmode-in-an-empty-scene.516004/#post-4117669