Search code examples
c#messagebox

Do I need to dispose of a MessageBox or will it take care of itself?


Do I need to dispose of a MessageBox or will it take care of itself?

I have the line of code:

MessageBox.Show(
    message, 
    title, 
    MessageBoxButtons.OK, 
    MessageBoxIcon.Information);

When the user hits the OK button and the dialog box goes away is it removed from memory?


Solution

  • The MessageBox class does not implement the IDisposable interface, so you cannot dispose an instance.

    Plus, as in your example, you are calling a static method, so there is no instance to dispose anyway.