如何处置固定文件 [英] How to dispose a FixedDocument
问题描述
在应用程序中,我创建一个FixedDocument作为打印预览。每当用户通过创建新的FixedDocument并替换documentviewer使用的旧数据来更改某些数据时,都会刷新此预览。
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.
问题是:FixedDocument包含大量资源
Problem is: the FixedDocument contains a lot of resources, some of them of type Image, created from ImageSources from resources.
该程序正在消耗内存并很快用完GDI句柄。
The program is eating up memory and runs out of GDI handles soon.
我的问题:如何处置FixedDocument,以便正确处理所有内容?
My question: how do I dispose the FixedDocument so all the content is disposed properly?
推荐答案
这是一个有相同问题的人:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/f5216805-5730-4be2-82fa-8a7e7757dd19
Here's someone with the same problem: http://social.msdn.microsoft.com/Forums/en/wpf/thread/f5216805-5730-4be2-82fa-8a7e7757dd19
找到另一篇有趣的文章:
http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx
Found another interesting article: http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx
我使用
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?
这篇关于如何处置固定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!