I asked this question here ([How do I fix a memory leak caused by an object referenced by a ContextMenuStrip](https://stackoverflow.com/questions/32507587/how-do-i-fix-a-memory-leak-caused-by-an-object-referenced-by-a-contextmenustrip)) and thought it had been answered, but the obvious fix did not work. I have searched about the problem, and found many questions and blogs about memory leaks due to ContextMenuStrips, but found no concrete answers. I have created a small WinForms test application that exhibits the problem. Upon creation of the project I add a TreeView to Form1 in the designer and modify Form1.cs as follows:

```
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        treeView1.NodeMouseClick += OnNodeMouseClick;

        var object1 = new MyObject("Object1");
        var object2 = new MyObject("Object2");
        var object3 = new MyObject("Object3");

        var treeNode1 = new TreeNode(object1.Name) { Tag = object1 };
        var treeNode2 = new TreeNode(object2.Name) { Tag = object2 };
        var treeNode3 = new TreeNode(object3.Name) { Tag = object3 };
        treeView1.Nodes.Add(treeNode1);
        treeView1.Nodes.Add(treeNode2);
        treeView1.Nodes.Add(treeNode3);
    }

    private void OnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        if (treeView1.SelectedNode == null)
            return;

        if (e.Button != MouseButtons.Right)
            return;

        MyObject targetObject = (MyObject)e.Node.Tag;

        if (targetObject == null)
            return;

        var point = new Point(e.X + 20, e.Y);
        var popupMenu = targetObject.PopupMenu;
        popupMenu.Show(this, point);
    }
}

```

I also have the MyObject class:

```
class MyObject
{
    public MyObject(string name)
    {
        Name = name;
    }
    public string Name { get; set; }
    public ContextMenuStrip PopupMenu
    {
        get
        {
            ContextMenuStrip myPopup = new ContextMenuStrip();
            myPopup.Items.Add(ItemDelete);
            return myPopup;
        }
    }

    public ToolStripMenuItem ItemDelete
    {
        get
        {
            ToolStripMenuItem itemDelete = new ToolStripMenuItem("Delete " + Name);
            itemDelete.Click += ItemDelete_Click;
            return itemDelete;
        }
    }

    public void ItemDelete_Click(object sender, EventArgs e)
    {
    }
}

```

I have not implemented the delete method as it is not needed to see the problem. Whenever you right click on an object in the tree a new ContextMenuStrip is created. The menus never get deleted. In my actual application the context menus can reference some large objects. The retention path shown in dotMemory has the ContextMenuStrip referenced by a UserPreferenceChangeEventHandler. How can I dispose of the menus after they close?