Am using COM interop in my C# application.
I've this line of code:
IMyInterface objData = MyCOMClass.GetData();
My question here is:
Do I need to release resources on objData by using? System.Runtime.InteropServices.Marshal.ReleaseComObject(objData);
Thanks for reading.
Yes, unless it is ok for you to wait until the GC cleans it up.
Could be worth noting that the COM interop creates one COM reference per Interface.
IMyInterface x = MyCOMClass.GetData();
IMyOtherInterface y = (IMyOtherInterface)x;
IMyInterface z = x;
Marshal.ReleaseComObject(x);
Marshal.ReleaseComObject(y);
or Marshal.FinalReleaseComObject(x); // If you know nobody else uses it
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