Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

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

Open
dngs365 opened this issue Nov 6, 2019 · 0 comments
Open

Comments

@dngs365
Copy link

dngs365 commented Nov 6, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant