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 want to make a form like this in windows forms. To make a
I have a windows forms; and there are several controls on it. I want
If I have a path, like so: c:\windows\system32\inetsrv\abc.exe And I want to make a
I have a bunch of controls derived from System.Windows.Forms.UserControl, which are then being displayed
I want to know if its possible to automate the System.Windows.Forms.WebBrowser and make it
I'm using LuaInterface for .NET to create Windows Forms objects. This works pretty good
I have simple Windows Forms application (not WPF), and I have two controls on
I have a Windows::Forms application and I want to add a custom control to
I am working in C# Windows Forms Application I want to make shadow of
I want to make an Windows application using C#.NET in which I capture video

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.