Trying to replace Controls.Clear() to avoid memory leak doesn’t work – why?

前端 未结 3 1567
攒了一身酷
攒了一身酷 2020-12-22 07:35

I replaced:

panel.Controls.Clear();

with:

Clear(panel);

Where:

public static void Clear(C         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 08:27

    You need remove controls you disposed, but there might be a better approach:

    public static void Clear(Control ctrl)
    {
        foreach(Control c in ctrl.Controls) c.Dispose();
        ctrl.Controls.Clear();
    }
    

提交回复
热议问题