读取.xps文件会导致OutOfMemoryException

时间:2016-05-09 08:59:01

标签: c# out-of-memory xps

当我使用c#读取.xps文件时,我得到OutOfMemoryException 我从Opening XPS document in .Net causes a memory leak获得了一些信息,但似乎在我的代码中无效。

我的代码如下:

using (XpsDocument document = new XpsDocument(xpsPath, System.IO.FileAccess.Read))
{
    FixedDocumentSequence fds = document.GetFixedDocumentSequence();

    int pageCount = fds.DocumentPaginator.PageCount;

    for (int i = 0; i < pageCount; i++)
    {
        DocumentPage source = fds.DocumentPaginator.GetPage(i);
        Visual v = source.Visual;
        FixedPage fixedPage = (FixedPage)v;

        fixedPage.UpdateLayout();
    }           
    document.Close();
}
  1. 当我删除行fixedPage.UpdateLayout()时。通过Win8&#34;任务管理器&#34;,当我读取一个.xps文件时,当前程序对内存的使用每次增加10MB。
  2. 当我添加此行时,内存的使用每次仍增加约1MB。
  3. 任何人都可以帮助我?

0 个答案:

没有答案