Search Issue Tracker
By Design
By Design in 2021.3.X
Votes
0
Found in
2020.3.40f1
2021.3.11f1
Issue ID
UUM-20873
Regression
No
"NativeCollection not disposed" error is thrown when recompiling scripts
How to reproduce:
1. Open the attached project “IN_15912”
2. Open “SampleScene” Scene
3. Go to PrimeTile → Demos → Scenes → Scenes
4. Open “AgentTarget” script
5. Add a comment and save
6. Observe the Console
Expected result: no error in the Console
Actual result: error in the Console
Reproducible with: 2020.3.40f1, 2021.3.11f1
Couldn’t test with: 2022.1.18f1, 2022.2.0b8, 2023.1.0a12 (due to compiler errors)
Full error: “A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.”
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
- Inspector loses focus or Material doesn't update when using GetModifiedMaterial with a Mask component
- Crash on GfxDeviceClient::AllocateBufferInternal when entering Play mode using Graphics.RenderPrimitives and Graphics.DrawProcedural in the scene
- Import TextMesh Pro window opens when the Text Mesh Pro Essentials and Examples are already imported when creating a new TextMesh Pro GameObject in the Hierarchy with TextMesh Pro settings reset
- Video is not rendered when the VideoPlayer GameObject is disabled and re-enabled after playback starts while using Material Override render mode
- Missing documentation page - "Sorry...that page seems to be missing" is shown on the browser when clicking the help icon on a Color Preset Library Scriptable Object
Resolution Note:
This behavior is correct. The key ingredients here are:
- A MonoBehaviour with attribute [ExecuteInEditMode] is using a NativeContainer
- The NativeContainer is being Dispose()'d in OnDestroy of this MonoBehaviour
This means OnDestroy won't be called for the instance of this MonoBehaviour in the editor domain. Moving the dispose code to OnDisable resolves the issue.
Resolution Note (2021.3.X):
This behavior is correct. The key ingredients here are:
- A MonoBehaviour with attribute [ExecuteInEditMode] is using a NativeContainer
- The NativeContainer is being Dispose()'d in OnDestroy of this MonoBehaviour
This means OnDestroy won't be called for the instance of this MonoBehaviour in the editor domain. Moving the dispose code to OnDisable resolves the issue.