简体   繁体   English

IronPDF 导致内存泄漏

[英]IronPDF Causing a Memory Leak

I am using IronPDF to generate PDF documents.我正在使用 IronPDF 生成 PDF 文档。 My program is a web app hosted on IIS that uses ChromePdfRenderer to render PDF using an HTML string, and it sequentially generates a bunch of documents.我的程序是一个托管在 IIS 上的 Web 应用程序,它使用 ChromePdfRenderer 使用 HTML 字符串呈现 PDF,并按顺序生成一堆文档。 I noticed over time, total memory used by the process increases and ultimately crashes.我注意到随着时间的推移,进程使用的总内存增加并最终崩溃。 Further investigation showed the unmanaged memory keeps increasing as it generates PDFs.进一步调查显示,非托管内存在生成 PDF 时不断增加。

I wrote a sample console app to replicate this我写了一个示例控制台应用程序来复制这个

public class PdfBenchmark{

    private static readonly ChromePdfRenderOptions ChromePdfRenderOptions = new ChromePdfRenderOptions
    {
        PaperSize = IronPdf.Rendering.PdfPaperSize.Letter,
        CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen,
        PrintHtmlBackgrounds = true,
        FitToPaper = true,

        EnableJavaScript = true,
        RenderDelay = 200,
        Timeout = 60
    };

    public async Task<Stream> SimplePdf()
    {            
        var renderer = new IronPdf.ChromePdfRenderer()
        {
            RenderingOptions = ChromePdfRenderOptions
        };

        renderer.RenderingOptions.HtmlHeader.MaxHeight = 25;
        renderer.RenderingOptions.HtmlHeader.DrawDividerLine = false;
        renderer.RenderingOptions.HtmlHeader.HtmlFragment = HeaderHTML;

        renderer.RenderingOptions.HtmlFooter.MaxHeight = 12;
        renderer.RenderingOptions.HtmlFooter.DrawDividerLine = true;
        renderer.RenderingOptions.HtmlFooter.HtmlFragment = FooterHTML;


        using (var x = await renderer.RenderHtmlAsPdfAsync("<h1>Html with CSS and Images and js</h1>"))
        {
            return x.Stream;
        }                
    }


    public const string FooterHTML = @"<div class='container-fluid'>some html</div>";

    public const string HeaderHTML = @"<div class='container'>
                                <div class='row header d-flex justify-content-between'>
                                    <div class='col-md-1 logo'>
                                    </div>
                                    <div class='col text-end right'>
                                        <div>>some HTML content</div>
                                    </div>
                                </div>
                            </div>";

    }
}

static async Task Main(string[] args)
{            
    var x = new PdfBenchmark();
    for (int i = 0; i < 200; i++)
    {
        using var stream = await x.SimplePdf();
        //Do whatever I want here...
        Console.WriteLine($"Created doc#: {i}");
    }
}

the larger the HTML, the quicker the memory usage grows. HTML 越大,内存使用量增长得越快。 Here's the memory profiler snapshot.这是内存分析器快照。

dotMemory 配置文件

You can see how unmanaged memory grew fast, but wasn't released after about 100 iterations.您可以看到非托管内存如何快速增长,但在大约 100 次迭代后并未释放。 I've reproduced this on .NET Core 3.1 and .NET Framework.我已经在 .NET Core 3.1 和 .NET Framework 上复制了这个。

Has anyone else had this issue and how did you resolve this?有没有其他人遇到过这个问题,你是如何解决这个问题的? IronPDF support has been useless so far. IronPDF 支持到目前为止一直没有用。

IronPDF acknowledged there was a memory leak in their Chrome renderer and they've fixed the issue. IronPDF 承认他们的 Chrome 渲染器中存在内存泄漏,他们已经解决了这个问题。 Fix is available from version 2021.11.4257 onwards.从 2021.11.4257 版本开始提供修复。

The memory leak is resolved in IronPdf update 2021.11.4257, released 2021-11-15. 2021-11-15 发布的 IronPdf 更新 2021.11.4257 中解决了内存泄漏问题。 https://www.nuget.org/packages/IronPdf/2021.11.4257 https://www.nuget.org/packages/IronPdf/2021.11.4257

  • Fixes memory leaks (see attached images below)修复内存泄漏(见下图)
  • Adds Installation.ChromeBrowserLimit添加 Installation.ChromeBrowserLimit
  • Adds AWS support.添加 AWS 支持。 Full Docker setup tutorial here - https://iron.helpscoutdocs.com/article/115-aws-lambda-amazon-linux-2 (this does not yet include support for AWS "Layers")完整的 Docker 设置教程在这里 - https://iron.helpscoutdocs.com/article/115-aws-lambda-amazon-linux-2 (这还不包括对 AWS“层”的支持)
  • Updated exception messages, to allow developers to diagnose more issues更新了异常消息,允许开发人员诊断更多问题
  • Several minor bug fixes几个小错误修复

What will be in our next update?我们的下一次更新会是什么? (known issues): (已知的问题):

Applying headers and footers to a document with a page count greater than 30 currently causes an issue, so to successfully apply headers and footers to documents with a page count greater than 30, you must add IronPdf.Installation.ChromeBrowserLimit = 50;将页眉和页脚应用于页数大于 30 的文档当前会导致问题,因此要成功地将页眉和页脚应用于页数大于 30 的文档,您必须添加IronPdf.Installation.ChromeBrowserLimit = 50; where "50" is greater than the expected page count of your large document.其中“50”大于大型文档的预期页数。

How long was there a memory leak?内存泄漏多久了?

Around November 1st in IronPdf 2021.11.4183 IronPdf 11 月 1 日左右 2021.11.4183

Why did this occur?为什么会出现这种情况?

Our Chrome renderer is relatively new unmanaged propriety code.我们的 Chrome 渲染器是相对较新的非托管专有代码。 A recent update caused a memory leak which was not captured due to inadequate extended performance profiling.最近的更新导致内存泄漏,由于扩展性能分析不足而未捕获该泄漏。

How will this be prevented in the future?未来将如何防止这种情况发生?

We have implemented extended performance profiling for our "continuous integration" process to ensure that both our managed and unmanaged code performance is up-to-par before releasing IronPdf to the public.我们已经为我们的“持续集成”过程实施了扩展性能分析,以确保我们的托管和非托管代码性能在向公众发布 IronPdf 之前达到标准。

2 files 2个文件2021.11.4183 确认内存泄漏 内存泄漏已在 2021.11.4257 中修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM