PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Needs to Dispose() GDI objects

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
Jaimi



Joined: 18 Dec 2007
Posts: 2

PostPosted: Tue Dec 18, 2007 8:03 pm    Post subject: Needs to Dispose() GDI objects Reply with quote

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.
Back to top
View user's profile Send private message
Vyacheslav Popov



Joined: 23 Nov 2007
Posts: 18

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

Please, send you code here Very Happy
Back to top
View user's profile Send private message Visit poster's website
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Dec 19, 2007 9:13 am    Post subject: Re: Needs to Dispose() GDI objects Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Jaimi



Joined: 18 Dec 2007
Posts: 2

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

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.
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Dec 19, 2007 5:13 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com