SkiaSharp memory leak on SubstituteFont event

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

3 Replies 1 reply marked as answer

MJ Mohanaselvam Jothi Syncfusion Team October 22, 2020 03:38 PM UTC

Hi Will,

Thank you for contacting Syncfusion support.

From the given details, we suspect that the problem might be due to contents in the input Word document, code snippet and the list of missed fonts in your production environment. We have prepared a sample application in ASP.NET Core using your code example and it can be download from the below link:
https://www.syncfusion.com/downloads/support/forum/158989/ze/Sample_application2146852541

Could you please share us the below things from your end:
  1. Modified sample of above with complete code snippets.
  2. Input Word document which used at your end.
  3. From the SubstituteFont event, share the list of missed fonts used in your production machine
  4. Details about the Syncfusion product version used at your end.
  5. Details about the SkiaSharp version installed in your application (1.59.3 or other)

If you are facing some difficulties to get the list of missed fonts which are used in input Word document means, you can run the below sample using you input Word document and you can get the list of missed fonts in UI:
https://www.syncfusion.com/downloads/support/forum/158989/ze/ShowMissedFonts842713093

Please let us know if you have any other questions

Regards,
Mohanaselvam J
 


Marked as answer

WC Will Chambers November 2, 2020 04:44 PM UTC

Hi Mohanaselvam ,
Thank you for your reply and apologies for the lateness of my response.

I have filled out the sample solution as best I can. It should show how I'm using the products. I don't feed in a word doc, it's all created in the application (as you can see in the solution). I have included in the zip an example word file (I simply saved the wordDoc that is created before converting to pdf) and a screenshot of the output pdf file. I also include a memory profile indicating no change if I unhook the event subscription (I had tried this already, but it wasn't in my original snippet).

Regarding the syncfusion version, I'm using 18.3.0.38.

I do not have any version of skiasharp installed as a package in my application. I assume the skiasharp references are coming from syncfusion's packages.

I hope this gives you enough to go on. Please let me know if you need more information,

Kind Regards
Will

Attachment: Documents_148e1135.zip


MJ Mohanaselvam Jothi Syncfusion Team November 3, 2020 10:48 AM UTC

Hi Will,

Thank you for sharing us the details.

A support incident to track the status of your query under your account has been created. Please log on to our support website to check for further updates,
https://www.syncfusion.com/account/login

Please let us know if you have any other questions

Regards,
Mohanaselvam J 


Loader.
Up arrow icon