Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dispose()

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
The code below was inserted by the forms designer. The components variable was set to null also by the forms designer. I saw no reason to override the Dispose method in this fashion because unless the components variable is not null it would do exactly what I think the regular Dispose method would have been doing. Can anyone explain how this relates to components and if it is reasonable to delete it?

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

Kyle
 
Hey Kyle,

well, I don't fully understand it myself, but I can tell you what I know: .NET provides its own gargage collection, which I believe the dispose command is linked to. So that code snipit is basically saying:
If I'm doing garbage cleanup, and there's a control, start disposing of the control to free up the resources.

Now your question was, &quot;Why override it?&quot; And the only answer I've come up with is that some function calls can only be done if they are overwritten. The code you gave will for sure dispose of any controls. Otherwise, you're left with relying on .NET to clean up the mess on its own.

Thats what I've gleamed in teh last few weeks anyway. Definately take it with a grain of salt and keep looking for other info sources, but it won't hurt your code to keep that dispose sub in.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top