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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:57:09+00:00 2026-05-13T06:57:09+00:00

Many times there is a clear method, that removes all the items from the

  • 0

Many times there is a clear method, that removes all the items from the collections, are these items disposed also.

Like,

toolStripMenuItem.DropDownItems.Clear();

is sufficient, or should I have to call like that:

foreach (ToolStripItem item in toolStripMenuItem.DropDownItems)
{
  toolStripMenuItem.DropDownItems.Remove(item);
  item.Dispose();
}

Edit: Well ToolStripItem is an example not a question, for those who says Clear is enough I found another example, TabControl has also item collection and clear method. But TabControls can have complex controls (at least I have), which needs to be explicitly Dispose (even if they are Disposed automatically at some point by GC, cause they take huge memory). I guess the best answer is divo comment to dispose the items, and then call clear.

  • 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-13T06:57:09+00:00Added an answer on May 13, 2026 at 6:57 am

    Q: Does?

    A: No – Clear does not dispose the items (they could be used in other parts of your application).

    So, if your ToolStripItems are standard .NET ones, should Clear be sufficient? After some reflection I’d say “probably not”.

    Yeah, this is true that if you will have any references to the ToolStripItem in other part of your application, the .NET GarbageCollector will destroy(use the class destructor) it automatically. But, it will not call the Dispose(true) method, that is, however, required for the form’s IDisposable components.

    Read a propos this and this.

    Actually, I believe that you will, however, need to explicitly Dispose your Items, like the ToolStrip’s Dispose method does (replace this by yourToolStrip):

    if (!this.Items.IsReadOnly)
    {
        for (int i = this.Items.Count - 1; i >= 0; i--)
        {
            this.Items[i].Dispose();
        }
        this.Items.Clear();
    }
    

    EDIT

    I also created the following thread to clarify this question more generally.

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

Sidebar

Related Questions

Many times I saw logging of errors like these: System.out.println(Method aMethod with parameters a:+a+
Many times I've seen links like these in HTML pages: <a href='#' onclick='someFunc(3.1415926); return
I've heard many times that all programming is really a subset of math. Some
Many times I have seen Visual Studio solutions which have multiple projects that share
Many times when I read books related to CSS I see things like this
Many times we find ourselves working on a problem, only to figure out the
Many times, a Java app needs to connect to the Internet. The most common
Many times I will use the same font scheme for static text in a
This is something I've pseudo-solved many times and have never quite found a solution
In order to know how many times a pattern exists in current buffer, I

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.