c# - WPF TextBlock memory leak when using Font -


i'm using .net 4.5 on windows 7, , might find memory leak.
have textblock (not textbox - it's not undo problem), changes value every second (cpu usage, time, etc...).
using .net memory profiler (and watching task manager) noticed memory keeps on growing. more accurate, see more , more live instances of unmanagedmemorystream (i tried gc.collect() didn't anything).

after tests, i've found out problem appears when i'm setting textblock font resource font follows:

<style targettype="{x:type textblock}">     <setter property="control.foreground" value="#cccccc"/>     <setter property="fontfamily" value="pack://application:,,,/myuicontrols;component/./fonts/#noto sans"/> </style> 

i tried updating text property directly code or via binding, behaves same both ways.

bottom line:
when fontfamily set, instances of unmanagedmemorystream keep on coming (forever) each time i'm updating text. when don't (set fontfamily property), memory stable.
(btw, happens when use label instead of textblock well)

it looks memory leak couldn't find reference it.
suggestions of how can solved?

a fontfamily leaks unmanagedmemorystreams when used if sourced embedded resource or relative path. when fontfamily sourced system font or absolute path, not leak.

you can here , download project reproduces problem.

workaround: resource fonts: save fonts temporary folder , use absolute path stored font. relative path fonts: resolve , use absolute path instead.


Comments