Hi,
I am printing to xps in this way:
PrintQueue queue = printQueueObject as PrintQueue; if (queue != null) { queue.Refresh(); collator = PrintQueue.CreateXpsDocumentWriter(queue).CreateVisualsCollator(); collator.BeginBatchWrite(); ... collator.Write(visual); collator.EndBatchWrite(); }
After 1000 pages or so are printed, I get an OutOfMemoryException. After using a memory profiler, the problem source seems to be the following chain:
InterleavingNode
-> System.Windows.Xps.Packaging.XpsFixedPageReaderWriter
-> _parentNode (field)
--> XpsFixedDocumentReaderWriter
--> _pageCache (field of type List<IXpsFixedPageReader>)
---> 800 instances of XpsFixedPageReaderWriter
-----> 2400 instances of System.IO.StringWriter = 2400 instances of System.Text.StringBuilder
or in other words:
There seems to be a page cache that is growing all the time, while we are generating the XPS document. So if we generate a huge document with many thousands of pages we get sooner or later an OutOfMemoryException (depending on the users available memory).
There has been a similar question here:
https://connect.microsoft.com/VisualStudio/feedback/details/788507/creating-xps-document-with-visuals-collator-consumes-a-very-large-amount-of-memory
But there has never been a solution or workaround to this. I am currently using Windows 8.
Thanks