mono / VulkanSharp

Open source .NET binding for the Vulkan API
MIT License
537 stars 61 forks source link

Why MarshalledObject does not free native memory even though disposing? #85

Open dngs365 opened 4 years ago

dngs365 commented 4 years ago

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.