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!
![]() |
Memory leak drawing RichTextBox to Canvas - SOLVED |
Post Reply ![]() |
Author | ||
Sopracenery ![]() Team Player ![]() ![]() Joined: 31 Aug 20 Location: Germany Status: Offline Points: 29 |
![]() ![]() ![]() ![]() ![]() Posted: 21 May 21 at 9:44PM |
|
Hi all, I have a memory leak using 18.11 when drawing content of a RichTextBox via Canvas to a new PDF doc. No problem with the first 15 pages. But reaching 20 or more pages the library on windows needs more and more time for each page and above 25-30 pages the system fails with Out Of Memory. Here are the commands I am using: fr.hdc = GetCanvasDC // get a canvas device context from the library and set it into the format range structure fr SendMessage(RTF.hWnd, EM_FORMATRANGE, True, fr) // Send text from a RichTextBox RTF to DC in fr LoadFromCanvasDC 1.422 1 fr.hdc = GetCanvasDC SendMessage(RTF.hWnd, EM_FORMATRANGE, True, fr) NewPageFromCanvasDC 0.203 2 fr.hdc = GetCanvasDC SendMessage(RTF.hWnd, EM_FORMATRANGE, True, fr) ... Repeat every page: (GetCanvasDC + SendMessage between every line not listed here) Method Time in seconds Page ============================================ NewPageFromCanvasDC 0.031 3 NewPageFromCanvasDC 0.031 4 NewPageFromCanvasDC 0.023 5 NewPageFromCanvasDC 0.031 6 NewPageFromCanvasDC 0.031 7 NewPageFromCanvasDC 0.039 8 NewPageFromCanvasDC 0.070 9 NewPageFromCanvasDC 0.094 10 NewPageFromCanvasDC 0.172 11 NewPageFromCanvasDC 0.305 12 NewPageFromCanvasDC 0.633 13 NewPageFromCanvasDC 1.102 14 NewPageFromCanvasDC 2.391 15 NewPageFromCanvasDC 4.344 16 NewPageFromCanvasDC 9.547 17 NewPageFromCanvasDC 17.383 18 NewPageFromCanvasDC 38.266 19 NewPageFromCanvasDC 69.586 20 Can anybody help? Martin Some more hints: I guess that each GetCanvasDC allocates memory and does not release it after NewPageFromCanvasDC. Calling CoTaskMemFree in ole32 with the pointer of fr.hdc has no effect. Only RemoveDocument or MergeDocument has effect in releasing memory. Edited by Sopracenery - 28 May 21 at 7:35PM |
||
![]() |
||
mLipok ![]() Senior Member ![]() ![]() Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
![]() ![]() ![]() ![]() ![]() |
|
Question.
Do this works well when you try it with single page ? I mean do you have properly created PDF ? |
||
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
||
![]() |
||
Sopracenery ![]() Team Player ![]() ![]() Joined: 31 Aug 20 Location: Germany Status: Offline Points: 29 |
![]() ![]() ![]() ![]() ![]() |
|
Hi Michał,
Sorry, I do not understand what you mean with „single page“. If I produce only one page then everything is fine. I can close the PDF and it is OK. My program is doing this now for months on thousands of documents. Normally producing 1-5 pages. But now that some documents need more than 20 pages I get this new error. Martin
Edited by Sopracenery - 26 May 21 at 11:17PM |
||
![]() |
||
mLipok ![]() Senior Member ![]() ![]() Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
![]() ![]() ![]() ![]() ![]() |
|
you said: "No problem with the first 15 pages"
What if your source document have only 1 page ? |
||
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
||
![]() |
||
Sopracenery ![]() Team Player ![]() ![]() Joined: 31 Aug 20 Location: Germany Status: Offline Points: 29 |
![]() ![]() ![]() ![]() ![]() |
|
If the source document in the RichTextBox has only one page then the output in PDF is only one page and anything is ok.
If I repeat sending this one page 20 times to to same PDF to generate more payload I get the same memory leak.
|
||
![]() |
||
Sopracenery ![]() Team Player ![]() ![]() Joined: 31 Aug 20 Location: Germany Status: Offline Points: 29 |
![]() ![]() ![]() ![]() ![]() |
|
After seaching in the completely wrong direction I finally found the reason why the library goes into trouble.
It is the option for font embeding in NewPageFromCanvasDC(dpi, Options) It can have the following values:
and I have chosen FontOption=4 which is the only one which leads into trouble. All others are working. So the library probably has a bug with option 4. Even when I do nothing else than repeated GetCanvasDC NewPageFromCanvasDC(dpi, 4) without printing anything to the canvas the memory runs out. Now I will use option 3 instead. Edited by Sopracenery - 29 May 21 at 5:17PM |
||
![]() |
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