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

  • SEARCH
  • Home
  • 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 3627826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:56:15+00:00 2026-05-18T23:56:15+00:00

I have this Dispose method I want to change. (Yeah I should check every

  • 0

I have this Dispose method I want to change. (Yeah I should check every object for null, I know)

    protected override void Dispose(bool disposing)
    {
        if( disposing )
        {
            if( monthLineBrush != null)
                monthLineBrush.Dispose();
            monthHeaderLineBrush.Dispose();
            shadowBrush.Dispose();
            monthHeaderLineBrushDark.Dispose();
            monthFontBrush.Dispose();
            weekendBgBrush.Dispose();
            whiteBrush.Dispose();
            dayFontBrush.Dispose();
            chartBrush.Dispose();
            chartWarningBrush.Dispose();
            barBrush.Dispose();
            monthLinePen.Dispose();
            monthHeaderLinePen.Dispose();
            monthHeaderLinePenDark.Dispose();
            warningLinePen.Dispose();
            monthFont.Dispose();
            yearFont.Dispose();
            weekLinePen.Dispose();
            dayLinePen.Dispose();
            tooltip.Dispose();
            toolTipLabel.Dispose();
        }

        base.Dispose(disposing);
    }

VS uses a System.ComponentModel.IContainer object named components , and only disposes this components object. Yet I can’t find any code where the different objects are added to the components objedct ??

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

How does this work ?

  • 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-18T23:56:16+00:00Added an answer on May 18, 2026 at 11:56 pm

    The code to add each object that is created to the components container is automatically generated and added to the *.Designer.cs file associated with each form by the designer.

    For example, the Form1.Designer.cs file might look something like this in a brand new, empty project once you’ve added a ToolTip control to the form:

    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        this.SuspendLayout();
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 264);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);
    }
    

    There are two relevant lines of code in that whole mess, the two that appear at the very top:

    this.components = new System.ComponentModel.Container();
    this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
    

    The first line creates a System.ComponentModel.Container object called components, to which all of the components that implement IDisposable will be added when they are created.

    The second line creates a ToolTip object (in response to one being drug to the form’s surface during design time), and uses a constructor overload that accepts a parameter of type IContainer.

    Extending this same song and dance to the other components that are added to your form allows them all to be disposed at one go with the Dispose method provided by the components container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this object PreloadClient which implements IDisposable , I want to dispose it,
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I want to do something mildly silly. In my Dispose() method for an object,
I have this code in jQuery, that I want to reimplement with the prototype
I know this has been discussed ad nauseum...but I have an issue with the
I have seen a question here where they implemented a generic dispose method that
I have a class which implements UserControl. In .NET 2005, a Dispose method is
The scenario I have, is in the Execute method of a SPJobDefinition I want
Can an ASP.NET web application have only one Init and one Dispose method or
I want to pass an event into a method. The code I have is

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.