.Dispose

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
When should I be using this?

And is it just for clearing things out of the memory or something?
 
I am creating a media app with the WMP plugin library.

Should i dispose of the player, id3 labels and album art when the track changes and new tags and music come on.

Or should i only dispose when i have totally finished with it.
 
The form and all components on it is disposed when it closes, this goes for default instances and new forms displayed with Show method. Forms showed as dialogs you dispose when finished retrieving dialog info, also here all components on form is disposed when you dispose the form. When you create new objects in code that implements idisposable you dispose them when finished with them. As mentioned in other thread, some objects Dispose method is paired with a Close method or similar that is sometimes more appropriate to use, documentation for the object is usually clear about this.

You only dispose objects that you create yourself, an example is a Graphics instance provided from the Paint event you do not dispose at end of event handler, but if created one using CreateGraphics or FromImage you do dispose. It may not be intuitive that FromImage method creates a new Graphics instance, but the documentation clearly states that you have Dispose when using this method.
 
Back
Top