Remove TabPage: Dispose or Clear or both?

.net, c#, tabcontrol, winforms

Solution

This snippet is from Control.Dispose:

        if (this.parent != null)
        {
            this.parent.Controls.Remove(this);
        }

Therefore you just have to call Dispose, not Clear.

Problem

I am working on a windows form that has a TabControl named tabDocuments. I came across this piece of code that removes all pages from the TabControl. ``` for (int i = tabDocuments.TabPages.Count - 1; i > -1; i--) { tabDocuments.TabPages[i].Dispose(); } tabDocuments.TabPages.Clear(); ``` The person who wrote this code has already left a while ago. I am trying to understand why the code is calling Clear() after disposing each of the tabPages (looks un-necessary to me). Can anyone please explain to me why? Or is calling Clear() extra?

Original source