简体   繁体   中英

User control does not dispose when dispose is called

I am using user control following way:

 Login = new MainMenu();
            Login.Parent = this;
            Login.Dock = DockStyle.Fill;
            Login.SelectionMade += new LoginS.SelectionMadeDelegate(menu_SelectionMade);
            Login.Show();

At some point, the user control fires an event, on which main form reacts like this:

   login.SelectionMade -= this.login_SelectionMade;
                    login.Dispose();

However when checking in debugger, the login instance is still not null. Why? It should be disposed I think

Calling dispose on an object does not set it to null. Dispose would clean up any resources used in the Login control.

You should use:

Login.Dispose();
Login = null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM