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!
How to release memory? |
Post Reply |
Author | |
alinux08
Team Player Joined: 20 Jun 12 Status: Offline Points: 20 |
Post Options
Thanks(0)
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 |
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
|
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. } |
|
alinux08
Team Player Joined: 20 Jun 12 Status: Offline Points: 20 |
Post Options
Thanks(0)
|
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 |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store