Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - How to release memory?
  FAQ FAQ  Forum Search   Register Register  Login Login

How to release memory?

 Post Reply Post Reply
Author
Message
alinux08 View Drop Down
Team Player
Team Player


Joined: 20 Jun 12
Status: Offline
Points: 20
Post Options Post Options   Thanks (0) Thanks(0)   Quote alinux08 Quote  Post ReplyReply Direct Link To This Post Topic: How to release memory?
    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





Edited by alinux08 - 18 Oct 12 at 1:35AM
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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.
    }


Back to Top
alinux08 View Drop Down
Team Player
Team Player


Joined: 20 Jun 12
Status: Offline
Points: 20
Post Options Post Options   Thanks (0) Thanks(0)   Quote alinux08 Quote  Post ReplyReply Direct Link To This Post 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


Edited by alinux08 - 18 Oct 12 at 5:04PM
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post 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!

Edited by tfrost - 18 Oct 12 at 11:19PM
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store