SkiaSharp
SkiaSharp copied to clipboard
[BUG] Memory leak occurs while measuring the text using font stream
Description
Memory keep on increasing while measuring the text using font stream
Code
for (int i = 0; true; i++)
{
Console.WriteLine(i);
// Memory leak occurs while measuring the text using font stream.
MeasureTextUsingFontStream();
}
// Measure the text using font stream
static void MeasureTextUsingFontStream() {
using (var stream = File.OpenRead(@"../../../arial.ttf")) {
using (var typeface = SKTypeface.FromStream(stream)) {
using (var paint = new SKPaint { Typeface = typeface }) {
// Issue doesn't occur if we commented the below line.
var width = paint.MeasureText("Hello, world!");
paint.Dispose();
}
typeface.Dispose();
}
stream.Dispose();
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
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
- Version with issue: 2.88.3
- Last known good version: None
- IDE: Visual Studio
- Platform Target Frameworks:
- Windows Classic: Windows 10
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
PASTE ANY DETAILED VERSION INFO HERE
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