On Windows 10, the System.Drawing.FontFamily.IsStyleAvailable method seems to leave the allocated space into memory even after the Dispose method has been called.
I wrote a simple console application to test it:
using System;
using System.Drawing;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static string getMemoryStatusString()
{
using (Process p = Process.GetCurrentProcess())
{
return "(p: " + p.PrivateMemorySize64 + ", v:" + p.VirtualMemorySize64 + ")";
}
}
static void Main(string[] args)
{
string s = getMemoryStatusString();
foreach(FontFamily fontFamily in FontFamily.Families)
{
Console.Write(fontFamily.Name + " " + getMemoryStatusString() + " -> ");
fontFamily.IsStyleAvailable(FontStyle.Regular);
fontFamily.Dispose();
Console.WriteLine(getMemoryStatusString());
}
string e = getMemoryStatusString();
Console.WriteLine(s + " -> " + e);
Console.ReadLine();
}
}
}
Any idea on why this is happening?
Thanks in advance!
fontFamily
, you don't own the object, it is still a member of theFamiles
collection. Any future enumerations of that collection will possibly error out. – Equalizer