开发者

User control does not dispose when dispose is called

开发者 https://www.devze.com 2023-02-17 10:05 出处:网络
I am using user control following way: Login = new MainMenu(); Login.Parent = this; Login.Dock = DockStyle.Fill;

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 开发者_StackOverflow社区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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号