I have an c# com class that is used by umamaged code. I can debug it , but I can't know when an object is released. If it had been implementd in c++ descructur would be called ,on c# it would be released to GC. Is there any way to track that moment? Thanks in advance.
Managed types that maintain unmanaged resources should implement the IDisposable interface. This tells consumers of your code that they need to call Dispose()
on instances of your object(s) when they are through with them (i.e., wrap them in a using
block when possible).
A proper implementation of IDisposable
will release the native resources in their finalizer, but clients can call Dispose()
sooner than that for deterministic release of unmanaged resources. Either way you avoid a leak, but it is better to call Dispose()
as quickly as possible.
Here is an SO question which details the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With