Increasing memory leak with batch writingHello All,<br/> <br/> I have a problem of increasing memory allocation when I use VisualsToXpsDocument to batch write a large number of pages (1000 pages) with print ticket to Xps document.<br/> <br/> Here is the code that I used:<br/> <p class=MsoNormal><span style="line-height:115%;font-size:x-small"><span> </span> <br/> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">      <span style="font-size:14px;color:#003300">// use batch writer with ticket</span> </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>   </span> <span><span>_</span> xpsBatchWriter</span> = static_cast&lt;VisualsToXpsDocument __gc*&gt;<span>  </span> <span>(_xpsDocumentWriter</span> -&gt;CreateVisualsCollator());</span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">    _xpsBatchWriter</span> <span style="line-height:115%;font-size:x-small">-&gt;BeginBatchWrite();<span>      </span> </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">for (int i = 0 ; i &lt; 1000 ; i++) </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">{</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small"> = __gc new PrintTicket();</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">      <span style="color:#33cc00"><span style="color:#009900">containerVisual</span> </span> = __gc new ContainerVisual();<br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> <span>pageMediaSize</span> = __gc new PageMediaSize(sz.Width, sz.Height); </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small">-&gt;PageMediaSize = pageMediaSize;</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small">-&gt;PageOrientation = </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> (sz.Width &gt; sz.Height)? PageOrientation::Landscape : PageOrientation::Portrait;</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> containerVisual</span> <span style="line-height:115%;font-size:x-small">-&gt;Children-&gt;Add(fixedPage);</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> <span>_xpsBatchWriter</span> -&gt;Write(<span>containerVisual</span> , <span>ticket</span> );</span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">}</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>  </span> <span>  </span> <span>  </span> _xpsBatchWriter</span> </span> <span style="line-height:115%;font-size:x-small"><span style="font-size:14px">-&gt;EndBatchWrite();</span> </span></p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt">The allocated memory will continue to increase with each page written.</p> <p class=MsoNormal style="margin-left:12pt">I don't know if there is some resources should be released or is it a bug at DotNet framework.</p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px"><br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">I'll be so thankful if anyone could help me.</span> </span></p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">Regards,</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">Hmeidi.<br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:8px"></span></p> <br/>© 2009 Microsoft Corporation. All rights reserved.Thu, 09 Jul 2009 12:23:06 Zd09ce67a-57b9-4f39-81e6-900e41319cc2http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#d09ce67a-57b9-4f39-81e6-900e41319cc2http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#d09ce67a-57b9-4f39-81e6-900e41319cc2Hmeidihttp://social.msdn.microsoft.com/Profile/en-US/?user=HmeidiIncreasing memory leak with batch writingHello All,<br/> <br/> I have a problem of increasing memory allocation when I use VisualsToXpsDocument to batch write a large number of pages (1000 pages) with print ticket to Xps document.<br/> <br/> Here is the code that I used:<br/> <p class=MsoNormal><span style="line-height:115%;font-size:x-small"><span> </span> <br/> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">      <span style="font-size:14px;color:#003300">// use batch writer with ticket</span> </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>   </span> <span><span>_</span> xpsBatchWriter</span> = static_cast&lt;VisualsToXpsDocument __gc*&gt;<span>  </span> <span>(_xpsDocumentWriter</span> -&gt;CreateVisualsCollator());</span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">    _xpsBatchWriter</span> <span style="line-height:115%;font-size:x-small">-&gt;BeginBatchWrite();<span>      </span> </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">for (int i = 0 ; i &lt; 1000 ; i++) </span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">{</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small"> = __gc new PrintTicket();</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">      <span style="color:#33cc00"><span style="color:#009900">containerVisual</span> </span> = __gc new ContainerVisual();<br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> <span>pageMediaSize</span> = __gc new PageMediaSize(sz.Width, sz.Height); </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small">-&gt;PageMediaSize = pageMediaSize;</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> ticket</span> <span style="line-height:115%;font-size:x-small">-&gt;PageOrientation = </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> (sz.Width &gt; sz.Height)? PageOrientation::Landscape : PageOrientation::Portrait;</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> containerVisual</span> <span style="line-height:115%;font-size:x-small">-&gt;Children-&gt;Add(fixedPage);</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>      </span> <span>_xpsBatchWriter</span> -&gt;Write(<span>containerVisual</span> , <span>ticket</span> );</span> </span></p> <p class=MsoNormal><span style="font-size:14px"><span style="line-height:115%;font-size:x-small">}</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:14px"><span style="line-height:115%;font-size:x-small"><span>  </span> <span>  </span> <span>  </span> _xpsBatchWriter</span> </span> <span style="line-height:115%;font-size:x-small"><span style="font-size:14px">-&gt;EndBatchWrite();</span> </span></p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt">The allocated memory will continue to increase with each page written.</p> <p class=MsoNormal style="margin-left:12pt">I don't know if there is some resources should be released or is it a bug at DotNet framework.</p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px"><br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">I'll be so thankful if anyone could help me.</span> </span></p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"> </p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">Regards,</span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="line-height:115%;font-size:x-small"><span style="font-size:14px">Hmeidi.<br/> </span> </span></p> <p class=MsoNormal style="margin-left:12pt"><span style="font-size:8px"></span></p> <br/>Wed, 11 Mar 2009 18:15:52 Z2009-04-15T08:01:13Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#5ea9a2ef-2529-420e-b72d-afddaaa5d07dhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#5ea9a2ef-2529-420e-b72d-afddaaa5d07dHmeidihttp://social.msdn.microsoft.com/Profile/en-US/?user=HmeidiIncreasing memory leak with batch writingI can hear my echo cuz no one replies!!Wed, 01 Jul 2009 14:33:12 Z2009-07-01T14:33:12Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#c876834a-43dc-4c82-ac25-1bba884bbfd4http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#c876834a-43dc-4c82-ac25-1bba884bbfd4Hmeidihttp://social.msdn.microsoft.com/Profile/en-US/?user=HmeidiIncreasing memory leak with batch writingWhere are Microsoft guys to defend their toolkit?<br/> <br/> I said that their is a memory leakage bug in DotNet Framework 3.5, am I wrong??<br/>Wed, 01 Jul 2009 14:36:37 Z2009-07-01T14:36:37Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#e6f27765-3ae8-4034-b42d-30c78d9ebc8ehttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/d09ce67a-57b9-4f39-81e6-900e41319cc2#e6f27765-3ae8-4034-b42d-30c78d9ebc8eJo0815http://social.msdn.microsoft.com/Profile/en-US/?user=Jo0815Increasing memory leak with batch writingmaybe same problem I've faced in the past... does it get better when you try following:<br/> <br/> a) calling Measure/Arrange/UpdateLayout to the Visual, and/or<br/> b) call UpdateLayout at least to one/first fixedPage of the FixedDocumentSequence<br/> <br/> maybe it helps!?<br/> <br/> regards,<br/> JoThu, 09 Jul 2009 12:23:06 Z2009-07-09T12:23:06Z