Content Add-ins leak memory on every call to Excel.run()
at a rate
large enough to eventually crash the add-in.
TaskPane Add-ins with exactly the same code do not display the same behaviour.
The amount of memory leaked ranges from 10MB to 100MB per Excel.run()
call.
The amount of memory leaked correlates with the complexity of the Excel.run()
batch function, such as the number of proxy objects and Excel.sync()
calls used.
Even an empty batch function leaks memory at a rate high enough to consume host memory and crash the Add-in.
Even code this trivial leaks up to 10MB per call:
export async function run() {
try {
await Excel.run(async context => {
return Promise.resolve(true);
});
} catch (error) {
console.error(error);
}
}
The memory leak is not permanent. After about twenty minutes it is freed but by
then the Add-in may have crashed already due to memory pressure, if many calls
to Excel.run()
have been made.
An almost trivial project which reproduces the problem is available here. It is based on the Microsoft Yeoman office-js generator.
The following gif shows what happens when I run the project and repeatedly click the 'Run' button. The memory usage of Excel in Task Manager constantly increases, to the point that many gigabytes will be consumed. Mysteriously, twenty minutes in the future the memory is reclaimed without any user interaction but not before this accumulated use of memory causes system or Add-in instablity problems.
This same project run as a TaskPane Add-in does not cause memory usage to increase at all.