Sahil Dudeja

Sahil Dudeja

  • NA
  • 6
  • 3.4k

Memory Leak Issues while loading PDF using FOXIT PDF SDK

Jul 10 2017 5:06 AM
Hi Experts,
 
I am new to C#. I am basically a core java developer. We are working on to load  PDF into RAM using Foxit PDF SDK. Another developer in team has used Task.Run() for this purpose, but we are seeing issue with it. If we load 71 pages of PDF, it takes 100+ MB of RAM and on closing PDF window, memory is not free. Each time we open PDF it takes, some RAM which is not released even after closing the window. It's only released after closing application. IF we open PDF a number of times, it results in AccessViolationException. Code is posted below:
 

try

{

FSDKBitmap sdkBitmap = new FSDKBitmap(nWidth, nHeight, (int)FSDKBitmap.bitmapFormat.FSCRT_BITMAPFORMAT_24BPP_BGR, IntPtr.Zero, 0);

System.Drawing.Color c = System.Drawing.Color.White;

System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, (int)nWidth, (int)nHeight);

sdkBitmap.fillBitmapRect(c, rect);

CRTInterface.FSDK_RenderPageByGE(pdfPage, nWidth, nHeight, pageRotation, sdkBitmap.m_bitmap);

Byte[] bitmapBuffer = sdkBitmap.getBuffer();

MemoryStream bufferStream;

Bitmap bitmap;

Bitmap bitmapcopy;

bufferStream = new MemoryStream(bitmapBuffer);

PageImage displayimage = new PageImage();

displayimage.pimage = BitmapToImageSource(bufferStream);

count++;

displayimage.X = 0;

displayimage.Y = (nHeight + 20) * count;

sdkBitmap = null;

bitmapBuffer = null;

GC.Collect();

}

catch (System.Exception e)

{

WriteToLog("RenderPageByGE_Initial" + " - " + e.Message);

}

Regards,
Sahil 

Answers (1)