Hi,
I am experiencing a memory leak when subscribing to the SubstituteFont event in DocIO. I have narrowed it down to this line - if I remove the line then the leak is not present.
I've attached screenshots of memory profiles with and without the event subscription and you can see a lot of font and SkiaSharp objects being held in memory even after the syncfusion components and the calling services have been disposed.
Please note that I've tried disposing everything that is disposable (including the PdfDocument "dicument"), tried using PdfDocument.ClearFontCache and tried using EnableMemoryOptimization. Is there any possibility of me being able to fix this issue in my code? Or if this is a bug that would require a fix on your end?
Many thanks
Will
Snippets below:
{
//...
wordDoc.FontSettings.SubstituteFont += SubstituteFont;
var wordDocConverter = new DocIORenderer { Settings = { EmbedFonts = true, EmbedCompleteFonts = true } };
var document = wordDocConverter.ConvertToPDF(wordDoc);
//...
wordDocConverter.Dispose();
wordDoc.Dispose();
var template = document.Pages[0].CreateTemplate();
page.Graphics.DrawPdfTemplate(template, new PointF(0, 0));
}
public async void SubstituteFont(object sender, SubstituteFontEventArgs args)
{
var bytes = //bytes from a ttf file
var memoryStream = new MemoryStream();
if (bytes?.Length > 0)
{
memoryStream = new MemoryStream(bytes);
args.AlternateFontStream = memoryStream;
}
else
{
args.AlternateFontName = "Arial";
}
}
Attachment:
skiasharpmemoryleak_8438e3d9.7z