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 351985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:41:41+00:00 2026-05-12T11:41:41+00:00

I want to make Windows Forms controls readonly and IDisposable. Is this is a

  • 0

I want to make Windows Forms controls readonly and IDisposable.

Is this is a good thing or a bad thing and what do I have to watch out for when calling Dispose?

I have a Tab (PageTab) that I extend and insert a Panel which has a listview and another Toolbar control into. These tabs then get inserted into a tab control (all native .NET Windows Forms controls).

When the user closes one of these tabs I call the Dispose method (which follows the MSDN way of implementing IDisposable).

Is it wise or suggested to declare the controls as read-only (see below)?

protected readonly ListView _AccountsList = new ListView();
protected readonly Panel _Panel = new Panel();

Because in the Dispose method I just call _Panel.Dipose(), etc. on them, but I cannot set them to null. I want to avoid leaks as much as I can and have things garbage collected.

What’s the best way for a non-Designer GUI development and disposing them?

  • 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-12T11:41:42+00:00Added an answer on May 12, 2026 at 11:41 am

    The default implementation of Control.Dispose (inherited by TabPage) is quite sufficient. It iterates the child controls as stored in the Controls collection member and calls their Dispose() method. You don’t have to help.

    There are only two cases where you should call Dispose() explicitly:

    • When you remove a control from the Controls collection. Calling Dispose() here is a hard requirement. Not doing so will keep the window handle alive for the life of the program, it is just not visible. You’ll have a leak if you don’t dispose it.
    • When you show a form with ShowDialog(). This bypasses the normal automatic disposal of a form and its child controls, necessarily so that you can read back the dialog result without risking an ObjectDisposed exception. The using statement is the proper way to do this.

    The latter case is not in fact a leak, the Control class’ finalizer ensures that the window handle for the dialog eventually is released, assuming there are no live references left to the dialog object.

    Control is one of the very few classes where forgetting to call Dispose() can in fact cause an uncontrollable resource leak. You are correct in that you have to call Dispose() explicitly on your TabPage derived object to dispose it when you remove the page. But you don’t have to worry about its child controls.

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

Sidebar

Related Questions

I have a bunch of controls derived from System.Windows.Forms.UserControl, which are then being displayed
I want to make sure that a set of functions have the same signature
I have a note editor control in my Windows Forms application: alt text http://img82.imageshack.us/img82/2033/tabtohiddencontrol.png
For the first time ever, I'm investigating RichTextBox controls in C# Windows forms. I
I want to make a WPF Window that behaves like a context menu. So,
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I want to make a copy of an ActiveRecord object, changing a single field
I want to make an entity that has an autogenerated primary key, but also
I want to make a .NET Form as a TopMost Form for another external

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.