tags:

views:

40

answers:

1

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.

+1  A: 

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

adrianm
Thanks adrianm for your response.This helps.
Jimmy