Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 369657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:56:28+00:00 2026-05-12T13:56:28+00:00

Is it necessary to manually manage the lifetime of System.Drawing objects? Currently I am

  • 0

Is it necessary to manually manage the lifetime of System.Drawing objects?

Currently I am employing ‘using’ statements to minimise the lifespan of Brushes and other Drawing objects e.g.

using ( Brush br = new SolidBrush( color ) )
{
    // Do something with br
}

Is this necessary or is it safe to let the garbage collector work its magic when and if it needs to?

As a quick aside to the question… what do people think is the cleanest way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:56:28+00:00Added an answer on May 12, 2026 at 1:56 pm

    It is good to Dispose of System.Drawing object, however if you miss one or two when you get an exception etc, it is not the end of the world. (Other objects like opened files and database connections must always be disposed)

    Having lots of “Using” statement all over your code make it more complex to understand. I would therefore in the case of System.Drawing object, consider just calling Dispose() on them at the end of the method.

    In the past I have used a class I written “Dustcart”, that implements IDisposable, and contains a collection of objects to dispose. You can then write code like:

    using(var dustcart = new Dustcard())
    {
       var p = dustcart.Add(new Pen(red, etc));
       var b = dustcart.Add(new Brush(black));
    
       Pen t;
       if (someFlag)
       {
          t = p;
       }
       else
       {
          t = dustcard.Add(new Pen(etc));
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it necessary to check for nullptr after allocating an object using gcnew?
My PHP script serves files using readfile() and manually added HTTP headers. Files are
It is necessary for my application to keep the camera captured until released manually
When it comes to using the terminal to build libraries manually and such I
For the CodeIgniter project I'm creating, it is necessary that users get activated manually
Does anyone know an easy way to use jQuery (or other Javascript if necessary)
I am using Marketpress with Wordpress on my site. Marketpress only protects necessary pages
I'm writing some DB routines and I'm using prepared statements. My environment is PDO
not necessary an UML diagram, just a simple way to graphically document the relations
I'm struggle extracting necessary data from this json stored inside php variable. Not yet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.