Print Page | Close Window

How to release memory?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2432
Printed Date: 06 Jun 25 at 8:21PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to release memory?
Posted By: alinux08
Subject: How to release memory?
Date Posted: 18 Oct 12 at 1:33AM
Hi, please help me on this one. I have done some search on this topic,  am still puzzled. 
My project is using DebenuPDFLibraryDLL0911 (C#, dll);

The following code is taken from the Getting Started DLL Edition page,
    int InstanceID;
    InstanceID = DPLCreateLibrary();
    if (DPLUnlockKey(InstanceID, "your license key") == 1) {
       DPLDrawText(InstanceID, 100, 500, "Hello world");
      DPLSaveToFile(InstanceID, "C:\Docs\HelloFromDLL.pdf");
    }
    DPLReleaseLibrary(InstanceID);

My problem is that I could not find the function of DPLReleaseLibrary(InstanceID) when I create an instance of the quickpdf library.

          PDFLibrary  qp = new PDFLibrary(@"DebenuPDFLibraryDLL0911.dll");

           qp.UnlockKey("**********");

           int filehandle = qp.DAOpenFile( "fname", "Password");
         
          after   qp.DACloseFile(fileHandle);

then how can I release the memory ? Is there one function like qp.DPLReleaseLibrary(InstanceID)?

Thanks.

Mark






Replies:
Posted By: AndrewC
Date Posted: 18 Oct 12 at 3:58AM
If you free the qp object then the C# wrapper will unload the DLL from memory when the qp destructor is called.  The DPLReleaseLibrary function is a low level DLL/C function that is automatically called in the qp destructor code.

The PDFLibrary destructor code calls Release() which does all the work for you automatically.

        public void Release()
        {
            if (dllHandle != IntPtr.Zero)
            {
                foreach (int instanceID in shutDownList)
                {
                    DebenuPDFLibraryReleaseLibrary(instanceID);
                }
                FreeLibrary(dllHandle);
                dllHandle = IntPtr.Zero;
            }
        }

When the qp variable is no longer used then it is released.
 
    void LoadPDF()
    {
           PDFLibrary  qp = new PDFLibrary(@"DebenuPDFLibraryDLL0911.dll");

           qp.UnlockKey("**********");

           int filehandle = qp.DAOpenFile( "fname", "Password");
          
          qp.DACloseFile(fileHandle);

          // Release is called here automatically when the qp variable is freed.
    }




Posted By: alinux08
Date Posted: 18 Oct 12 at 4:56PM
Andrew, thanks for the quick reply. Do you mean that after  qp.DACloseFile(fileHandle) is called the memory is automatically released by the C# wrapper ? no more action required from me?

Just to be safe, do I have to set the qp = null?

Inside my app, multiple instances of Quickpdf library are created at the same time, I don't want the app to be messed up without releasing the memory after finishing the job.

One more question about multiple thread safety, if multiple instances of Quickpdf library are created at the same time,

will the the following function call inside C# wrapper release all the memory, or only the memory of the calling instance ( qp.DACloseFile(fileHandle) ) will be released?
  
 public void Release()
        {
            if (dllHandle != IntPtr.Zero)
            {
                foreach (int instanceID in shutDownList)
                {
                    DebenuPDFLibraryReleaseLibrary(instanceID);
                }
                FreeLibrary(dllHandle);
                dllHandle = IntPtr.Zero;
            }
        }



Thanks again

Mark


Posted By: tfrost
Date Posted: 18 Oct 12 at 10:32PM
Surely no C# programmer (I cannot claim to be one) has ever had to release or free anything explicitly.  Or so they never tire of boasting!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk