Re: Not disposing StringFormat?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Its good form to dispose of any object that you create if it is disposable. In the case of many GDI+ objects, StringFomat included, the System.Drawing classes are in fact nothing more than a wrapper around the unmanaged GDI+ library. This means that the management of unmanaged objects is important especially if you want good graphical performance.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"JS" <jnospamster@xxxxxxxxx> wrote in message news:e0e125fd-f916-41ff-ad78-74397d8d230f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks Bob. I hadn't noticed the static properties on StringFormat,
but it makes sense that you'd want to clone these before modifying.
I've always done a new StringFormat() and then set it up. The problem
was, I didn't notice that StringFormat was disposable (and the
Microsoft examples didn't help). It would be nice if Intellisense or
the VS editor highlighted the IDisposable objects somehow.

The current release of my software is not disposing some of these
objects -- I am guessing that there could be several thousand
StringFormat objects that I have not released because I found one of
them in the OnPaint of a UserControl that I wrote. I'm not sure how
serious of a problem this is.

.



Relevant Pages

  • Re: StringFormat with DrawString
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... If I remove my StringFormat from the DrawString call, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Not disposing StringFormat?
    ... If you need to use a modified string format based on one of the standard ones you should clone, for example, GenericTypeographic, modify it, use it and dispose of it. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... MSDN has lots of examples where they create StringFormat instances ... anyone knows of symptoms I should watch for from customer problem ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: GDI objects count
    ... Are these GDI objects or GDI+ objects? ... forgetting to call Dispose()? ... Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: MeasureString
    ... Remember that you must clone the GenericTypographic StringFormat object ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Disposing Images
    ... If the ImageList owns the images it will dispose of them, ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.windowsforms.controls)