Closed MilkyChestnut closed 1 month ago
Hi @MilkyChestnut,
Almost all things "Native" need to be allocated and disposed since you are creating memory allocations outside of managed memory. So, you are like 95% of the way to a final solution for your INetworkSeriaizable
implementation.
Within your Dispose method if you make this minor adjustment you should no longer get that error message when you completely disconnect from the session and most likely things are being destroyed:
public void Dispose()
{
if (_arrayInts.IsCreated)
{
_arrayInts.Dispose();
}
}
The IsCreated
property will let you know if the NativeArray is "created"/"allocated" or not in order to know whether you need to dispose it or not.
Let me know if this resolves your issue?
I believe this works, thanks I appreciate it!
I do have some serious issues with NativeArrays and NativeLists that Ill discuss is another issue report.
NativeLists dont seem to want to serialize at all, and NativeArrays wont serialize any custom structs implimenting INetworkSerialize (tho will work with other serialization methods)
Description
I'm using a custom struct implementing INetworkSeriaizable for a NetworkVariable. This custom struct has a NativeArray of ints and is created with the Allocation.Persistent
I've found that I keep getting this error.
Leak Detected : Persistent allocates 4 individual allocations.
When I impliment IDisposable however I get this error
Reproduce Steps
5) Add IDisposable, and impliment disposing of the array 6) Play again and when finishing the play session recieve the error about the array already being disposed.
Actual Outcome
Erros releated to a memory leak of not disposing the native array.
Errors related to the native array already being disposed when implimenting IDisposable
Expected Outcome
No errors about a memory leak or already disposing the NativeArray
Screenshots
Environment