One of my recent assignment when my BLL(Business Logic Layer) was consuming a COM+ component, I've seen at the testing environment in COM+ explorer that interop dlls after being accessed by my code , don't die immediately and moreover it takes lots of time to getting deactivate as it was obvious visually from the COM+ explorer of the 'Test Server'.
Hence I, after googling a bit add the following two lines of code, forcefully try to release the components
System.Runtime.InteropServices.Marshal.ReleaseComObject([Instance Of COM Component] );
[Instance Of COM Component] = null;
But please note that A common approach for releasing unmanaged objects is to set the RCW reference to null and then call System.GC.Collect followed by System.GC.WaitForPendingFinalizers. This is not recommended for performance reasons, because in many situations it can trigger the garbage collector to run too often. Code written by using this approach significantly compromises the performance and scalability of server applications. You should let the garbage collector determine the appropriate time to perform a collection.
No comments:
Post a Comment