May 27, 2015 at 9:16 PM
Edited May 27, 2015 at 9:18 PM
It will help to figure out whether the memory being used is part of the .NET managed heap or not.
For this you can make a macro that forces garbage collection and show the total managed memory usage:
public static void CheckMemory()
long managedMemory = GC.GetTotalMemory(true);
// Somehow log or display managedMemory
If this number is fairly stable, you know that the increase in the process's working set is not due to your .NET code.
For managed memory, you should be able to attach a profiler to figure where the memory is going.
There was a recent issue with Excel-DNA regarding the RTD servers, fixed more recently that version 0.32:
If the memory that concerns you is not managed memory, it's one of two things:
- Excel-DNA marshaling leaking memory
- Excel itself using more memory over time.
There are a number of cases where Excel seems to use increasing amounts of memory. For example, there is the Undo stack. And Excel seems to have some internal string caching, so writing different strings to cells will cause increasing memory usage.
The general strategy for these is to make a minimal reproduction using either VBA or a native C add-in, and then report to Microsoft.
If you struggle the pin the issue down, I'd be happy to help if you can make a minimal project that reproduces the issue.