1

I'm using Microsoft Excel interop in a windows service application to generate excel reports. Since I'm using interop assembly, need to ensure there are no memory leaks.

I have tried to handle the memory leaks through code by disposing (close, quit, assign null) all excel interop components like worksheet, workbook, excel application. But i want to confirm whether the fix to handle memory leak scenarios is working properly.

For this purpose, I'm using performance monitor tool and added .Net CLR interop pointing to windows service counter to the performance monitor. But, I'm not sure on how to confirm or validate for the metrics defined such as # of stubs, # of CCWs. What should be the values of the metrics that could confirm that there are no memory leaks in the windows service application using Microsoft Excel interop libraries.

Please suggest the method to confirm or calculate that there are no memory leaks using performance monitor.

user3220129
  • 503
  • 9
  • 24
  • Aside from using a performance monitor, you could just check the running processes. If everything has been released when you close/quit, the `Excel.exe` process will end. If not, it won't. – MrBlue Apr 06 '14 at 22:39

1 Answers1

0

You should watch "Private Bytes" in the performance monitor, if it increase continuously, then it means you have memory leaks.

You're using C# to call excel, so it should be RCW(Runtime callable wrapper, C# code calls native code), not CCW(COM callable wrapper, native code call C# code). One kind of memory leak comes from this wrapper. You can use the tool DebugDiag to track the memory leak, if it shows some leaks comes from "ole*.dll", which means you have leaks from the wrapper. RCW and CCW both use COM as a bridge, COM use reference counting to manage object life time, so if there're memory leak, it usually means the reference count of some object are not zero.

I spent my last week on tracing memory leaks from CCW, good luck!

Community
  • 1
  • 1
Matt
  • 6,010
  • 25
  • 36