Skip to content

Instantly share code, notes, and snippets.

@superstructor
Last active March 20, 2020 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superstructor/9614c9ab1110590332294bce1e987f75 to your computer and use it in GitHub Desktop.
Save superstructor/9614c9ab1110590332294bce1e987f75 to your computer and use it in GitHub Desktop.

Content Add-ins Leak Memory Eventually Crashing Add-in

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.

@superstructor
Copy link
Author

office-js 2020-03-20 13-44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment