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
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
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