ImportedPageArea

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v8)  /  ImportedPageArea

DynamicPDF CoreSuite for .NET (v8) Forum

 Aug 03 2017 1:19 PM
Hello Support Team,

We really like the ImportedPageArea Class because of it's efficient memory usage. It appears that it does not open the entire file, which we really like. However we noticed this object is not IDisposable, and I think from previous discussions the Draw method releases resources, is that correct? I noticed importedPageArea.Draw(pagewriter) and was hoping to release memory resources on each page while looping. I'm trying to figure out how to implement (derive) your Abstract classes PageWriter? Can you provide direction on this? The online documentation doesn't show implementation.

thanks for your help


using ceTe.DynamicPDF;
using ceTe.DynamicPDF.Imaging;
using ceTe.DynamicPDF.Merger;
using ceTe.DynamicPDF.Rasterizer;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.IO;

public static MergeDocument (thumbNailList tnl)
{
        MergeDocument mergeDocument = new MergeDocument();
        Document document = new Document();
        int index;

        try
        {
                //DocWriter dw = new DocWriter();
                //dw.Draw();
                //OpWriter ow = new OpWriter();
                //ow.DocumentWriter.Draw();
                //PageWriter pw = ow.PageWriter;


                for (int i = 0; i < tnl.Count; i++)
                {
                        index = tnl[i].PageIndex;
                        ImportedPageArea importedPageArea = new ImportedPageArea(tnl[i].PDFFilePath, index, 0, 0);
                        importedPageArea.Angle = tnl[i].RotationDegrees > 0 ? tnl[i].RotationDegrees : importedPageArea.Angle;
                        
                        Page page = new Page(PageSize.Letter, PageOrientation.Portrait);
                        page.Elements.Add(importedPageArea);
                        
                        document.Pages.Add(page);

                        //importedPageArea.Draw(pw);
                }
                mergeDocument.Append(new PdfDocument(document.Draw()));
        }
        catch (OutOfMemoryException ex)
        {
                // Do to: re-throw error
        }
        return mergeDocument;
}
 Aug 18 2017 4:58 PM
Posted by a ceTe Software moderator
Hello,

ImportedPageArea and other page elements do not implement IDisposable because these objects need until the main Draw method is called. The main Draw method automatically flags these resources for destruction after execution. It is not possible to derive from PageWriter class and release the resources of each individual ImportedPageArea within the loop. Although there is a Draw method available on ImportedPageArea (and other page elements) it is called internally when the main Draw method is executed. Once the main Draw method finishes generating the final PDF it flags all resources (ImportedPageArea & other page elements used) for destruction and after that.NET garbage collector is responsible for releasing the resources.

Thanks,
ceTe Software Support Team.
 Aug 18 2017 5:10 PM
The document.draw method below never releases internal memory created by the ImportedPageArea object.

ImportedPageArea importedPageArea = new ImportedPageArea(tnl[i].PDFFilePath, index, 0, 0);

mergeDocument.Append(new PdfDocument(document.Draw()));


Please see link below for the approach we created to ensure memory release per page

http://www.dynamicpdf.com/Forums/DisplayThread.csp?FD=56&ThreadID=3692#35386

 Aug 21 2017 2:27 PM
Posted by a ceTe Software moderator
Hello,

Since our API is a 100% .NET managed library, destruction and release of managed objects/resources is handled by the .NET Framework itself. Due to the inherent nature of .NET memory management, the .NET Common Language Runtime (CLR) controls the assignment and release of memory for all the .NET managed objects. Regardless of whether you use ImportedPageData or ImportedPageArea objects, the Draw() method upon successful execution flags all the resources for destruction. After this point it is up to the .NET Garbage Collector to release the internal memory occupied by the objects that are flagged for destruction. How and when this Garbage Collector runs is up to the .NET Common Language Runtime (CLR).   

You may force the Garbage Collector to run by explicitly calling the GC.Collect() method. However, calling GC.Collect() is not typically recommended and should be used with caution. For more on this topic please refer to the following Microsoft Developer Blog post.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 3:50 AM.