-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Memory leak occurs while measuring the text using font stream #2446
Comments
Could you try to create the typeface outside the loop? You will most likely not see any increase in memory usage. Skia is caching glyphs data and is only clearing the cache if it reaches some defined memory usage level. |
@Gillibald, Thanks for the update. Yes, as you mentioned memory leak doesn’t occur if we create the typeface outside the loop. But for our requirement, we need to create a typeface for every looping. So, is there any possibility to forcibly dispose the memory by using any API’s? |
@Gillibald & @mattleibow - Any solution for this? It would be very helpful for us. |
Why do you need it though? |
@FoggyFinder - Please find the below requirement details, We are working on the Word document to PDF conversion project, and we are using the SkiaSharp library to measure the width and height of the text by using an embedded font stream in the document. While converting multiple (more than 100) Word documents to PDF in for loop, memory keeps on growing until the loop ends due to creating more number of SKTypeface for each Word document. Since each Word document may have a different set of embedded font streams, it’s not possible to create SKTypeface commonly (outside of the loop). To avoid this memory leak problem, we expected to dispose the SKTypeface allocated memory after completing each conversion. Could you please help us to solve this memory problem? Note: At certain stage, app crashed with out of memory problem. |
@FoggyFinder & @Gillibald & @mattleibow - Any help would be much more appreciated. |
You can also set your own limits in the cache via
|
I had same memory leak issue when using At the end I solved memory leak by encapsulating and caching output of public static SKTypeface? GetTypefaceFromFile(string filename)
{
return typefaceCache.GetOrAdd(filename, filename => SKTypeface.FromFile(filename) ?? null);
} |
Description
Memory keep on increasing while measuring the text using font stream
Code
Note: You can use any available TTF font to replicate this problem.
Expected Behavior
Allocated memory should be disposed properly
Actual Behavior
Memory allocation increasing rapidly without any disposal
Basic Information
OS:
OS - Windows 10 Pro
Processor - Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz 2.71 GHz
Installed RAM - 16.0 GB (15.9 GB usable)
System type - 64-bit operating system, x64-based processor
Screenshots
Measuring the text using font stream: (Memory keep on increasing here)
Measuring the text using installed font: (Memory disposed properly here and it's maintained in same level)
Reproduction Link
Please use the attached sample to replicate the same problem,
SkiaSharpTesting.zip
The text was updated successfully, but these errors were encountered: