Procedural Mesh leaks memory everytime the game object is deleted in the editor

Each time i delete the game object, its mesh seem to be still existing. Is there something explicitly i have to do to delete the mesh?

I tried delete the mesh in OnDisable() using DestroyImmediate but the side effect is the mesh gets deleted if i hide the gameobject.

Am creating a mesh from scratch like this:

public class RouteCmp : MonoBehaviour {

    ...

    [SerializeField]
    Mesh m_Mesh=new Mesh();

    void Awake()
    {
        GetComponent<MeshFilter>().mesh = m_Mesh;
        GetComponent<MeshCollider>().sharedMesh = m_Mesh; 
    }

    public void BuildMesh()
    {
        ...
        ...

        this.Mesh.Clear();
        this.Mesh.vertices = vVertices;
        this.Mesh.colors = aColors;
        this.Mesh.uv = vVertUV;
        this.Mesh.triangles = nTriangleIndex;

    }
}

The image shows the before and after screen shots Click here

Currently the best you can do is to delete the mesh in OnDisable() like you mentioned yourself.

If you want to avoid deleting the mesh when hiding the GameObject, you can delete the mesh in your own function (say, MyDestroy), and manually call that function when you know you are about to destroy the GameObject for real (not just hiding it).

The mesh is not garbage collected because the engine still keeps a reference to it. You can find the meshes you have created by using FindObjectsOfType(), even if no GameObject currently keeps a reference to it. This is also why it is shown in the editor.

If you want to make Unity garbage collect objects that are not currently used, you can use Resources.UnloadUnusedAssets() - this is also called by Unity whenever you load a new scene. However, in your case it is definitely better to destroy the mesh yourself since you know it is not needed by other objects.