I have a console application that automates another windows application through COM interop. It automates the app开发者_JAVA技巧lication to open a file, take a screen shot and then exits.
I was wondering if there would be any ill effects if I didn't call Marshall.ReleaseComObject on the limited number of com objects that are getting instantiated? It seems cleaner to call the release method to clean up the objects but is it really necessary in this case?
Is it necessary? Probably not. But if you don't, I can almost guarantee that at some point this will come back and bite you. Whenever I'm using an unwrapped COM object, I always wrap it in a try...finally block and perform a ReleaseComObject
in the finally.
精彩评论