rdvojmoc / DinkToPdf

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
MIT License
1.09k stars 417 forks source link

Possible memory leak on 1.1.2 #98

Open Tri125 opened 4 years ago

Tri125 commented 4 years ago

In our netcore 2.2 MVC project we're using DinkToPdf to generate a bunch of PDF from a cshtml template.

We're registering a SynchronizedConverter as a singleton to inject it into our services:

services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

and our usage looks like that:

foreach (var questionnaireInformation in zipInformation.QuestionnaireInformations)
{
     var s = await this.viewRenderService.RenderViewAsync(controller, "~/Views/myTemplate.cshtml", model);

     var pdf = this.pdfConverter.Convert(new HtmlToPdfDocument
     {
         GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4 },
         Objects =
         {
             new ObjectSettings
             {
            UseLocalLinks = true,
                PagesCount = true,
                HtmlContent = s,
                WebSettings = { DefaultEncoding = "utf-8"},
             }
         }
    });

    // Write pdf to a stream, etc.
}

We were already using DinkToPdf for individual pdf but when we started to generate hundred of them together like in the example above, we noticed that the memory would go through the roof and it would never be garbage collected. A quick memory snapshot tells me that the count of some objects related to DinkToPdf are increasing.

drewgierach commented 4 years ago

@Tri125 I can confirm your assumptions. We are experiencing the same issue.

SeanLeitzinger commented 4 years ago

@Tri125 @drewgierach Did you guys ever confirm the memory leak issue?

Tri125 commented 4 years ago

@SeanLeitzinger

Well I'm pretty confident that there's a leak because of what I described above. It's up to the dev team to analyse our report and see what's going on.

SeanLeitzinger commented 4 years ago

I don't think this repository is maintained anymore. I'm in the process of building out the Html To Image functionality and will probably see if I can duplicate the leak on the PDF side as well.