PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 16, 2024 8:55 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Sep 03, 2009 2:54 pm 
Offline

Joined: Fri Mar 20, 2009 12:39 pm
Posts: 5
I'm now using the PDFSharp 1.3 in my little project and I found that when I use XFont, the memory usage goes up very quickly. And if I create about 50 XFont objects, the memory usage would exceeds 200Mb. My project is a small one, thus, such an memory usage is not acceptable.

I have dived into the source code a bit and found that FontData class used a lot of memory. And the issue is that there is no way to free the allocated memory that FontData class uses as far as I can see.

I can see that it seems that FontDataStock class holds the memory and it doesn't free it.
Is there a way to address this? Or is there a walk around solution?

I know that PdfSharp probably uses FontDataStock to cache the font data for performance's sake, but I think it would be better if a way to reclaim the memory is provided.

FYI, my program uses the office 2007 like live preview so that it creates different XFont objects when user is hovering one font family and that cause the going up of the memory usage.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 03, 2009 3:44 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
50 XFont objects?

Fonts should only be added once to FontDataStock.
If you create 50 XFont objects for "Courier,10", the memory usage should stay low (otherwise there is a bug).
FontDataStock.UnregisterFontData is not yet implemented.

imgen wrote:
FYI, my program uses the office 2007 like live preview so that it creates different XFont objects when user is hovering one font family and that cause the going up of the memory usage.

Workaround: So this preview shouldn't use XFont objects.

Hack: add a setter to "public static FontDataStock Global" that allows you to set it to null (when the users hover over fonts).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 04, 2009 3:22 pm 
Offline

Joined: Fri Mar 20, 2009 12:39 pm
Posts: 5
About the live preview: I'm creating XFont objects with different font families, so the memory usage is huge if a lot of XFont with different font families are created.

About the UnregisterFontData method, I also noticed that it didn't have a implementation.

About the walkaround: If not XFont, what choices do I have?

About the hack, the issue is that FontDataStock is an internal class so that if I want to access it, I have to make it a public class which will make a lot classes have to be public. This fact makes it not practical to do so.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 07, 2009 7:26 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
imgen wrote:
About the hack, the issue is that FontDataStock is an internal class [...]


Or just use "InternalsVisibleTo" in PDFsharp's AssemblyInfo.cs.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 12, 2009 5:58 am 
Offline

Joined: Fri Mar 20, 2009 12:39 pm
Posts: 5
Thanks a lot, now the problem is solved. You're the hero.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 153 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group