Loading...

Releasing Memory Usage

Support for GdPicturePDF Plugin.

Releasing Memory Usage

Postby coolwater » Wed Dec 28, 2011 9:17 am

I'm trying to load a PDF file, make sure that all pages will fit in 8.5x11 and add header and footer information. I noticed that memory usage doesn't drop after closing the pdf object. I've attached a sample code below that recreates the issue.

FYI, that I removed unnecessary information and the sample code might not do anything, but just demonstrate that memory usage will not drop after the the method TestMemory() is complete.

Our application just use part of GdPicture, and we don't want the memory to linger after we're done, or depend on GC to release the image. Using a the following PDF file http://www.testingexperience.com/testingexperience02_10.pdf as an example, there's approx 200MB committed memory that is not released after usage. That's a lot in our environment.

I'm using 8.5.0.1 version of GdPicture. Thanks!

Code: Select all
        public void TestMemory(string fileSpec)
        {
            var pdf = new GdPicturePDF();
            pdf.LoadFromFile(fileSpec, false);

            for (var pageNo = 1; pageNo <= pdf.GetPageCount(); pageNo++)
            {
                pdf.SelectPage(pageNo);

                using (var gdImage = new GdPictureImaging())
                {
                    var imageId = pdf.RenderPageToGdPictureImage(200F, false);
                    gdImage.ReleaseGdPictureImage(imageId);
                }
            }
            pdf.CloseDocument();
        }
coolwater
 
Posts: 8
Joined: Wed Nov 09, 2011 6:45 pm

Re: Releasing Memory Usage

Postby Loïc » Wed Dec 28, 2011 2:52 pm

Hi,

This is a typical .NET behavior. The garbage collector has not yet liberated all unused memory. This will be done later, when your app will need to allocate memory or when your app process will be in "idle" state.
I suggest you to let the .NET environment to manage this behavior but if you want to reclaim the free memory by yourself you can call the GC.Collect();

More info about GC.Collect: http://msdn.microsoft.com/en-us/library/xe0c2357.aspx
More info about .NET memory management: http://msdn.microsoft.com/en-us/magazine/bb985010.aspx

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4437
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Releasing Memory Usage

Postby wydler » Mon Mar 12, 2012 4:16 pm

Hi,

I have the same problem but I'm using Delphi and GdPicture as COM-Object. This is my example code:

Code: Select all
                                                                                       // Memory
  m_GdPicture := CreateComObject(CLASS_GdPictureImaging) as GdPictureImaging;          // 4676K

  m_ImageId := m_GdPicture.TiffCreateMultiPageFromFile( 'C:\...\9051000058.tif');      // 7192K

  if (m_GdPicture.AutoDeskew(m_ImageId) <> GdPictureStatus_OK) then                    // 46552K
    ShowMessage('Error: ' + IntToStr(m_GdPicture.GetStat));                           
  if (m_GdPicture.FxBitonalRemoveIsolatedDots4(m_ImageId) <> GdPictureStatus_OK) then  // 75860K
    ShowMessage('Error: ' + IntToStr(m_GdPicture.GetStat));                           
  if (m_GdPicture.FxGrayscale(m_ImageId) <> GdPictureStatus_OK) then                   // 75852K
    ShowMessage('Error: ' + IntToStr(m_GdPicture.GetStat));                           
  if (m_GdPicture.FxStretchContrast(m_ImageId) <> GdPictureStatus_OK) then             // 101648K
    ShowMessage('Error: ' + IntToStr(m_GdPicture.GetStat));                           
  if (m_GdPicture.ConvertTo1BppAT(m_ImageId) <> GdPictureStatus_OK) then               // 77832K
    ShowMessage('Error: ' + IntToStr(m_GdPicture.GetStat));                           
                        //
  m_GdPicture.ClearGdPicture;                                                          // 76736K
  m_GdPicture.ReleaseGdPictureImage(m_ImageId);                                        // 76736K


How can I drop all allocated memory?

Kind regards
wydler
 
Posts: 1
Joined: Fri Mar 02, 2012 12:48 pm

Re: Releasing Memory Usage

Postby Loïc » Mon Mar 12, 2012 5:18 pm

Hello,

How can I drop all allocated memory?


From a non managed environment of development you can't ask to the garbage collector to release all memory. This is done automatically.

I also suggest to put.
Code: Select all
m_GdPicture.ReleaseGdPictureImage(m_ImageId);   

before
Code: Select all
GdPicture.ClearGdPicture;   



Another test you can do to check for memory leak is to run your code in a loop. If the memory consumption continue to growing you have a memory leak.

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4437
Joined: Tue Oct 17, 2006 10:48 pm
Location: France


Return to GdPicture PDF Plugin

Who is online

Users browsing this forum: No registered users and 1 guest