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
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
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