I felt the design of structs are bad. But I can understand that because there is so many arrays to be flat memory.
However, memory leaking is another context.
I wondered that why samples are not dispose any of IDisposables such like infos.
I got the NativeReference handle this and it frees the native memory when destructed.
But, as you know, the destructor and finalizer are not guaranteed to be called.
Therefore we must call the Dispose() manually.
But NativeReference is a internal class.
So we have to call MarshalledObject.Dispose() instead which is public.
BTW, it dose not calling NativeReference.Dispose() at all.
It also leave it to destructor.
In the end, there is no chance to guarantee to prevent memory leaking.
I felt the design of structs are bad. But I can understand that because there is so many arrays to be flat memory. However, memory leaking is another context.
I wondered that why samples are not dispose any of
IDisposable
s such like infos. I got theNativeReference
handle this and it frees the native memory when destructed. But, as you know, the destructor and finalizer are not guaranteed to be called.Therefore we must call the
Dispose()
manually. ButNativeReference
is ainternal
class. So we have to callMarshalledObject.Dispose()
instead which ispublic
. BTW, it dose not calling NativeReference.Dispose() at all. It also leave it to destructor.In the end, there is no chance to guarantee to prevent memory leaking.