> I'm adding a significant amount of server controls to a dataGrid on a
> webform at runtime.  Server controls are mostly textboxes, dropdowns, and
> labels.  Should I manually dispose each control after adding it to avoid
> weighing down the server?
> 
> I'm doing something along these lines:
> 
> Loop {
> Dim myControl as new system.web.ui.webcontrols.SomeControl
> myGrid.item(i).cells(ii).add(myControl)
> myControl.Dispose()
> }
> 
> I'm wondering if disposing the control would even help; does the dataGrid
> still hold a reference to it, or a copy of it?

All the Dispose() method does in the Control base class is remove subscribed
event clients, and because the entire page and all of its controls is going
to be available for garbage collection as soon as your request is finished
processing, I see no advantage to calling Dispose() explicitly in this case.

        -Fritz

Fritz Onion
http://staff.develop.com/onion/

Essential ASP.NET
The class: http://www.develop.com/courses/essentialasp.net/
The books: http://www.develop.com/books/essentialasp.net/

Reply via email to