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
- [Render Graph Viewer] Resource list icons cropped and in inconsistent positions
- Scene View with Debug Draw Mode enabled is gray when GPU Resident Drawer is enabled
- The UI is not visible when resizing out of focus built Player window with Application.runInBackground set to false
- [Linux] "Error while reading movie" errors are thrown when opening templates
- Standalone Profiler process is hidden in macOS dock
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