Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track release of com object c#.

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.

like image 269
user629926 Avatar asked Nov 13 '22 07:11

user629926


1 Answers

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.

like image 59
Ed S. Avatar answered Nov 16 '22 04:11

Ed S.