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.
or
Marshal.FinalReleaseComObject(x); // If you know nobody else uses it