PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 12:49 pm

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: Tue Dec 18, 2007 8:03 pm 
Offline

Joined: Tue Dec 18, 2007 7:56 pm
Posts: 2
I'm evaluating PDF libraries - This is a nice library, but it doesn't appear that you are disposing your objects. Sorry in advance for the lecture, but all of the GDI+ objects have Dispose() methods because they have unmanaged resources behind them. This will result in memory and resource usage that the GC has no knowledge of, leading to increased memory and resource usage.

If I end up using your library, I will of course add changes to dispose the objects. Are you interested in these changes? Since I need VS2003 compatibility, I would be using the .9 code base.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Dec 18, 2007 9:42 pm 
Offline

Joined: Fri Nov 23, 2007 12:10 pm
Posts: 18
Please, send you code here :D


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 19, 2007 9:13 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Jaimi wrote:
I'm evaluating PDF libraries - This is a nice library, but it doesn't appear that you are disposing your objects. Sorry in advance for the lecture, but all of the GDI+ objects have Dispose() methods because they have unmanaged resources behind them. This will result in memory and resource usage that the GC has no knowledge of, leading to increased memory and resource usage.

The GDI+ objects also have Finalizers that call Dispose() - if GC disposes objects automatically, the Finalizer will be called and the Dispose() method is called automatically.
If the application terminates, the Finalizer may not be called for all objects - but the operation system will free the resources.
I checked Font and Pen and I can't see a resource leak for those.
And I don't think there's a resource leak for other GDI+ objects either.

Calling Dispose() will only free the objects earlier, but I don't see a real advantage here.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 19, 2007 3:00 pm 
Offline

Joined: Tue Dec 18, 2007 7:56 pm
Posts: 2
Well, I've tried to post several links to you in different ways to help out with understanding why you should dispose objects that have unmanaged resources. However, your phpbb setup will not allow me to post links, and eats any replies that contain them, regardless of how I enter the link.

They all boiled down to this: The GC has NO knowledge of unmanaged resources. Unmanaged resources (such as pen, brush, and font handles) are finite. The GC will only free up and finalize things when it feels there is pressure to do so, but it doesn't take into consideration the unmanaged resources.; Since the finalizer is not called automatically when something goes out of scope (IMO, the biggest flaw in C#), the Dispose method was invented to free up resources like this.

This is my last response on this topic - I'm just trying to help. If you don't want that help, that's fine. I will just keep my changes to myself.
I have 20 years of experience writing large and small software systems, 5 years of that in C#. I've been to Microsoft, attended the PDC's (spoken to Anders Hejlsberg on this very subject!). My applications process checks and print millions of bank statements every month - approximately 5% of the US market (no I'm not rich, though). In this sort of environment, you have to really be careful with memory and resources.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 19, 2007 5:13 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Jaimi wrote:
Well, I've tried to post several links to you in different ways to help out with understanding why you should dispose objects that have unmanaged resources. However, your phpbb setup will not allow me to post links, and eats any replies that contain them, regardless of how I enter the link.

They all boiled down to this: The GC has NO knowledge of unmanaged resources. Unmanaged resources (such as pen, brush, and font handles) are finite. The GC will only free up and finalize things when it feels there is pressure to do so, but it doesn't take into consideration the unmanaged resources.; Since the finalizer is not called automatically when something goes out of scope (IMO, the biggest flaw in C#), the Dispose method was invented to free up resources like this.

This is my last response on this topic - I'm just trying to help. If you don't want that help, that's fine. I will just keep my changes to myself.
I have 20 years of experience writing large and small software systems, 5 years of that in C#. I've been to Microsoft, attended the PDC's (spoken to Anders Hejlsberg on this very subject!). My applications process checks and print millions of bank statements every month - approximately 5% of the US market (no I'm not rich, though). In this sort of environment, you have to really be careful with memory and resources.


I didn't want to upset you. In general all contributions are welcome.
This forum has a new anti-Spam module (we cannot control that, sorry) that will reject anything that looks like a URL (including the using-statements of C# code). Users registered for 5+ days with 5+ posts are no longer filtered.

You can call
Code:
      GC.Collect();
      GC.WaitForPendingFinalizers();
anytime to make sure that all unneeded GDI+ resources are disposed.
That's one way to go; you suggest to call Dispose() in PDFsharp to free those resources; that's another way to go - and probably the better way.

So far I haven't heard of problems with PDFsharp caused by limited GDI+ resources.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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: Google [Bot] and 358 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group