I'm doing some ASP.NET development in VS and have just found an interesting little code suggestion (I think they come from coderush but I could be wrong).
Whenever I'm creating controls it tells me that I should be using a "using" statement for them. I'm a bit confused as to what is going on here though. with the using my code looks something like:
using (HtmlTableRow tableRow = new HtmlTableRow())
{
tableRow.Attributes.Add("class", isOddRow ? "OddRow" : "EvenRow");
listingTable.Rows.Add(tableRow);
addCell(tableRow, row, "issueId");
addCell(tableRow, row, "Title");
addCell(tableRow, row, "Type");
addCell(tableRow, row, "Summary");
}
So I am expecting that at the end of the using statement it will call dispose on the tableRow. However, the docs in MSDN library says:
The Dispose method leaves the Control in an unusable state. After calling this method, you must release all references to the control so the memory it was occupying can be reclaimed by garbage collection.
So I would expect that I now have an unusable object in my control structure so it would break or not render or something. However, everything seems to work just fine.
So what I'm wondering is why are all controls disposable? Is it just because some of them will be and making them all disposable means that one call to dispose at the top level can then be passed down to all child controls recursively?
I think I'd understand if not for the fact that the docs explicitly say that disposing of a control makes it unusable... Are the docs just wrong?