I developing a custom addin for Microsoft PowerPoint. My addin needs to store large amount of binary data into PowerPoint presentation. I store this binary data as base 64 encoded strings into PowerPoint presentation tags. I found, that when presentation contains huge amount of data in its tags (like 10+ megabytes), PowerPoint seems to be leaking memory when saving the presentation. So when such presentation is saved multiple times, PowerPoint even my run out of system memory and crash.
I developed a very simple C# addin to isolate the issue. It stores 50 megabytes of binary data into presentation when new presentation is created:
private void Application_AfterNewPresentation(PowerPoint.Presentation presentation)
{
int tagLength = 5 * 1000 * 1000;
StringBuilder largeTagValue = new StringBuilder();
largeTagValue.Capacity = tagLength + 2;
for (int i = 0; i < tagLength; i++)
{
largeTagValue.Append("A");
}
largeTagValue.Append("\0");
string largeTagValueString = largeTagValue.ToString();
for (int i = 0; i < 10; i++)
{
presentation.Tags.Add("LARGE_TAG" + i.ToString(), largeTagValueString);
}
}
After running this addin, I may even disable it to make sure that it not does anything more. Next, I am saving the presentation multiple times and see that PowerPoint memory usage in process list grows each time I save the presentation.
The complete source code and sample presentation is available here
Does anyone know if it is a PowerPoint bug or is there any workaround for this?...
Or, maybe there is another way to store relatively large amount of data into PowerPoint presentation?