The improvement consists of two parts:
1) Slide's title is retrieved from the generated slide rather than from the original one. There is no need to load and parse the content for the slide twice (once for the original slide and once for the new one during generation)
2) The source XDoc for generating a slide is retrieved using slide.GetXDocument(), then it saves the XDocument in the .Annotation<XDocument>(). So, there is a direct reference from the original slide to the new one. That's why the generated slides are not collected by GC (they were collected after the original PresentationDocument disposal).
You can see the difference in memory results below (execution is paused before srcDoc disposal).
Code:
[Fact]
public void MemoryTest()
{
var sourcePath = @"TESTFILE.pptx";
var openSettings = new OpenSettings { AutoSave = false };
using (var srcStream = File.Open(sourcePath, FileMode.Open))
using (var srcDoc = OpenXmlExtensions.OpenPresentation(srcStream, false, openSettings))
{
var index = 1;
foreach (var slide in PresentationBuilder.PublishSlides(srcDoc, sourcePath))
{
index++;
}
}
}
The improvement consists of two parts: 1) Slide's title is retrieved from the generated slide rather than from the original one. There is no need to load and parse the content for the slide twice (once for the original slide and once for the new one during generation) 2) The source XDoc for generating a slide is retrieved using
slide.GetXDocument()
, then it saves theXDocument
in the.Annotation<XDocument>()
. So, there is a direct reference from the original slide to the new one. That's why the generated slides are not collected by GC (they were collected after the original PresentationDocument disposal).You can see the difference in memory results below (execution is paused before
srcDoc
disposal).Code:
Before:
After: