- Home /
Unity logs an error whenever I try to deallocate a nativearray, is there a proper way to do it?
The code used for disposal is a simple
private void OnDestroy()
{
triangulationData.Dispose();
}
Not sure if the error is there, or if i didnt allocate it properly It was allocated with
NativeArray triangulationData;
triangulationData = new NativeArray(cell.roads, Allocator.Persistent);
ot sure when i went wrong, had a look on google and unity answers and couldnt see anything about this issue
Answer by andrew-lukasik · Feb 27, 2021 at 11:16 AM
If you're seeing an error when calling nativeCollection.Dispose();
it's because Dispose()
was called for this allocation already and possibly somewhere completely elsewhere.
As this is a race condition issue, to fix it, make sure this array has only one clearly defined owner who's job is to deallocate it and nobody else is. If your class isn't the owner of this allocation - don't dispose it. Only then this error will go away.
Your answer
Follow this Question
Related Questions
C# script failing silently? 0 Answers
Texture disappears in standalone (fine in editor)? 1 Answer
GooglePlayServices & GoogleMobileAds 0 Answers
"Health" value doesn't change? 1 Answer
Is there a way to tell unity not to debug a certian error? 1 Answer