开发者

How to dispose a FixedDocument

开发者 https://www.devze.com 2023-03-03 08:44 出处:网络
In an application I create a FixedDocument as preview of my print. This preview is refreshed whenever the user changes some data by creating a new FixedDocument and replacing the old one used by the d

In an application I create a FixedDocument as preview of my print. This preview is refreshed whenever the user changes some data by creating a new FixedDocument and replacing the old one used by the documentviewer.

Problem is: the FixedDocument contains a lot of resources, some of them of type Image, created from ImageSources from resources.

The program is eating up memory and runs out of GDI handles soon.

My question: how do I dispose the FixedDocument s开发者_StackOverflow社区o all the content is disposed properly?


Here's someone with the same problem: http://social.msdn.microsoft.com/Forums/en/wpf/thread/f5216805-5730-4be2-82fa-8a7e7757dd19

Maybe it helps?

Found another interesting article: http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx

I use the

        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();

pattern after attaching the new FixedDocument at the DocumentViewer. So for me the memory usage isn't growing too bad. But it's an ugly workaround.

Take a look at the "Bitmap" section of the article, maybe it applies to you?

0

精彩评论

暂无评论...
验证码 换一张
取 消