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 - Memory leak drawing RichTextBox to Canvas - SOLVED
  FAQ FAQ  Forum Search   Register Register  Login Login

Memory leak drawing RichTextBox to Canvas - SOLVED

 Post Reply Post Reply
Author
Message
Sopracenery View Drop Down
Team Player
Team Player
Avatar

Joined: 31 Aug 20
Location: Germany
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sopracenery Quote  Post ReplyReply Direct Link To This Post Topic: Memory leak drawing RichTextBox to Canvas - SOLVED
    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
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 21 at 7:45AM
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
Back to Top
Sopracenery View Drop Down
Team Player
Team Player
Avatar

Joined: 31 Aug 20
Location: Germany
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sopracenery Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 21 at 11:16PM
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
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 21 at 8:01AM
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
Back to Top
Sopracenery View Drop Down
Team Player
Team Player
Avatar

Joined: 31 Aug 20
Location: Germany
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sopracenery Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 21 at 9:13AM
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.
Back to Top
Sopracenery View Drop Down
Team Player
Team Player
Avatar

Joined: 31 Aug 20
Location: Germany
Status: Offline
Points: 29
Post Options Post Options   Thanks (1) Thanks(1)   Quote Sopracenery Quote  Post ReplyReply Direct Link To This Post Posted: 28 May 21 at 7:34PM
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:

Options-1 = Convert the drawing commands to a single image using GDI+
0 = Process the drawing commands as vector graphics, fonts are not embedded
1 = Process the drawing commands as vector graphics, fonts are embedded but not compressed
2 = Process the drawing commands as vector graphics, fonts are embedded and compressed
3 = Process the drawing commands as vector graphics, fonts not in the no embed font list are embedded and compressed
4 = Same as 3 but fonts already added during previous calls to this function or the LoadFromCanvasDC function are reused
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
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