2
            //Create a User Control with a TextBlock
            TextBlock textBlock = new TextBlock();
            textBlock.Text = "Helo";
            UserControl userCOntrol = new UserControl();
            userCOntrol.Content = textBlock;

            //Add the UserControl to a Table
            table.RowGroups[0].Rows[0].Cells[0].Blocks.Add(new Paragraph(new InlineUIContainer(userCOntrol as UIElement)));

            //Add the table to a FlowDocument
            FlowDocument flowDocument = new FlowDocument();
            flowDocument.Blocks.Add(table);

            //Fetch the Visual representation of the page.
            DocumentPage page = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator.GetPage(0);


            //Extract the Visual from the page and add to a Fixed Page
            FixedPage fixedPage = new FixedPage();
            ContainerVisual container = new ContainerVisual();
            container.Children.Add(page.Visual);
            DrawingCanvas canvas= new DrawingCanvas();
            canvas.AddVisual(container);
            fixedPage.Children.Add(canvas);


            //now write the FixedPage to an XPS file
            using (XpsDocument xpsDoc = new XpsDocument("c:\\x.xps", FileAccess.ReadWrite))
            {
                XpsDocumentWriter xpsDw = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
                xpsDw.Write(kj);
            }

上記のコードは何も解放しません。フロー ドキュメントがページ付けされ、ページのビジュアル表現がフェッチされると、フロー ドキュメントのコンテンツがビジュアルによって参照されます。そのため、ビジュアルもフロードキュメントの内容も破棄されません。上記のコードを実行すると、メモリ不足が継続的に発生しました。

これらすべてのリソースによって保持されているメモリを解放する方法を知っている人はいますか?

前もって感謝します。

4

0 に答える 0