How to dispose a FixedDocument

≡放荡痞女 提交于 2019-12-11 16:05:00

问题


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 so all the content is disposed properly?


回答1:


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?



来源:https://stackoverflow.com/questions/5883779/how-to-dispose-a-fixeddocument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!