Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>FlowDocument uses System.Windows.Threading.Dispatcher to free all resources. It doesn't use finalizers because finalizers will block current thread until all resources will be free. So the user may see some UI freezings and so on. Dispatchers are running in background thread and have less impact on the UI.<br> So calling GC.WaitForPendingFinalizers(); has no influence on this. You just need to add some code to wait and allow Dispatchers to finish their work. Just try to add something like Thread.CurrentThread.Sleep(2000 /* 2 secs */);</p> <p>EDIT: It seems to me that you found this problem during debugging of some application. I wrote the following very simple test case (console program): </p> <pre><code> static void Main(string[] args) { Console.WriteLine("press enter to start"); Console.ReadLine(); var path = "c:\\1.rtf"; for (var i = 0; i &lt; 20; i++) { using (var stream = new FileStream(path, FileMode.Open)) { var document = new FlowDocument(); var range = new TextRange(document.ContentStart, document.ContentEnd); range.Load(stream, DataFormats.Rtf); } } Console.WriteLine("press enter to run GC."); Console.ReadLine(); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("GC has finished ."); Console.ReadLine(); } </code></pre> <p>I've tried to reproduce the problem. I run it several times and it was working perfectly - there were no leaks (about 3,2Kb all of the time and 36 handles). I couldn't reproduce it until I run this program in debug mode in the VS (just f5 instead of ctrl+f5). I received 20,5Kb at the beginning, 31,7Kb after loading and before GC and 31Kb after GC. It looks similar to your results.<br> So, could you please try to reproduce this problem running in release mode not under the VS?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload