HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
366 stars 66 forks source link

Memory overflow #114

Closed NickYuanyang closed 1 month ago

NickYuanyang commented 1 year ago

In Docker, I use foreach, 10,000+ runs。Each PDF is about 79 + KB。The memory keeps getting bigger and bigger at any time, just filling up the memory。How to solve it? Are there any unmanaged objects that have not been released?

HakanL commented 10 months ago

Sorry for the late response. You should have just one instance of the PdfTools and just call that multiple times. I have used this in production for many years, but that being said, I only run a handful of PDFs per day, it's possible there are some memory leaks that I'm not aware of. But definitely you need to start with a singleton.

kijanawoodard commented 7 months ago

I'd wager this is "normal memory greedy behavior for dotnet server processes". Try using DATAS in .net 8. I've seen dramatic reductions in memory usage so far.

https://maoni0.medium.com/dynamically-adapting-to-application-sizes-2d72fcb6f1ea

key line for csproj file: <GarbageCollectionAdaptationMode>1</GarbageCollectionAdaptationMode>