1

I'm using the PrivateFontCollection class to add some font into memory dynamically.

_PrivateFontCollection.AddFontFile(string.Format("FontAddress{0}.ttf,_FontName);

I have a web browser in my win form application,for each page i use an unique font and before showing each page i load it's page font to memory.each font get 176KB of my memory, so i want to dispose loaded font for previews page from memory (for example release font "P1" form my font collection) How can i do this?

sloth
  • 99,095
  • 21
  • 171
  • 219
KF2
  • 9,887
  • 8
  • 44
  • 77
  • 1
    you would probably need to have a different PrivateFontCollection for each page and Dispose it when you change page – Paolo Falabella Nov 28 '12 at 08:08
  • How many fonts are you planning to use? – Good Night Nerd Pride Nov 28 '12 at 08:26
  • Have you tried `_privateFontCollection.Families[x].Dispose()`, where `x` is the index of the font you want to release from memory? However, I don't know how this affects the state of `_privateFontCollection`. You might have to make sure, it does not try to use the disposed font again. It might even be impossbile to re-add this font to the collection (in case the user pages backwards). – Good Night Nerd Pride Nov 28 '12 at 08:32
  • @Abbondanza:About 604 fonts. – KF2 Nov 28 '12 at 11:07
  • @Abbondanza:_privateFontCollection.Families[x].Dispose() donot work – KF2 Nov 28 '12 at 11:13
  • @irsog Then you either have to accept the cost of `604 * 176KB = 98MB` or do it like Paolo Falabella proposed above: use a `PrivateFontCollection` for each page. – Good Night Nerd Pride Nov 28 '12 at 11:21
  • Take a look at http://stackoverflow.com/questions/26671026/how-to-delete-the-file-of-a-privatefontcollection-addfontfile for a possible solution – Horcrux7 Oct 31 '14 at 13:53

0 Answers0