sábado, 12 de noviembre de 2011

.NET Interop pitfalls

I faced a few issues on the Migration Utility when loading COM objects (VB) from .NET and I want to share fixes so you could avoid wasting hours of your life.


Don’t trust on VB class Terminate event: it does not get fired! I load lots of SUI_WEB.SUI_Container objects and I was having a memory leak since memory is released internally on this event, even if you call Marshal.ReleaseComObject() and then set it to null.


Call Marshal.ReleaseComObject() method when you no longer need it: yes, we are coding on a managed code environment but if COM object is expensive, it’s recommended.


Don’t use two dots on a single line: .net wrappers seems to be not releasing objects for us, more details in links below.

http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp

http://www.velocityreviews.com/forums/showpost.php?s=f87f0674feda4442dcbd40019cbca65b&p=528575&postcount=2


No hay comentarios: