Hi I have a project migrated from VB6 to C# and using many Interop COM objects written in either C++ or VB6 by other team. The problem is when we finish one application (windows), sometimes it stays in memory so we have to kill it using Task Manager. But the same program is a part of web suit which can be used as a service. So each time a user use this using a webpage it stays in memory and keep holding the memory. We use COM objects in this way.
Interop.Sales.SomeClass Obj = new Interop.Sales.SomeClass();
if (obj.prop1.Prom2[1].item[0].prop == something)
....
My question is should we have to just clean the root object at the end like this
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null; // will it release all underlying objects created when accessing them?
or have to clean its each child object created in memory when accessing? like
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj.prop1.Prom2[1].item[0].prop);
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj.prop1.Prom2[1].item[0]);
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj.prop1.Prom2[1]);
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj.prop1);
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
My problem is that the project have more than 15000 lines of code and COM Interop objects are used at many places using the same way. If I have to follow the second way then it could be a very long and risky task. Please guide me the best solution to release all objects in COM Interop.
Thanks
QF