How to prevent editor to set the scene dirty if a script changes a mesh (@ExecuteInEditMode)

I've got a script that manages a custom mesh and needs to run in the editor. It works like intended, but changing the mesh (say by calling "GetComponent().sharedMesh.Clear()") causes the scene to set it's state to dirty (the * in the editor's titlebar shows up permanently and indicates a changed scene).

As I generate the mesh by code there's no reason for the user to save those changes, so is there a way to disable this behavior?

This must be possible somehow as the buildin ParticleSystem both runs in the editor and changes it's mesh without setting the scene dirty.

Update: I tried HideFlags.DontSave but without luck. As soon as I change some vertices the scene went dirty.

Update 2: Like tranquility suggested, I've tried the following:

[ExecuteInEditMode]
public class Meshtest : MonoBehaviour {
    Mesh mMesh;

    void OnEnable () {
        mMesh = new Mesh(); // create a private mesh
    }

    void Update()
    {
            mMesh.Clear(); // scene will turn to dirty state
    }
}

but even without any MeshFilter and MeshRenderer present in the scene it will turn to changed state immediately.

Changes to "sharedMesh" are persistent, for example, if you change it in play mode, changes will be kept after exiting play mode, scene will be changed. If you change MeshFilter's "mesh" property, changes will disappear after exiting play mode. Unfortunately, seems like you can not change "mesh" property in edit mode.

What you could do is creating one or more Mesh you want to show and use Graphics.DrawMesh. If you want to keep "sharedMesh" intact as part of your game object, but want to hide it, disable MeshRenderer component.


EDIT: I set hideFlags and it worked - private mesh changes don't make scene dirty.

void OnEnable () 
    {
        mMesh = new Mesh(); // create a private mesh
        mMesh.hideFlags = HideFlags.HideAndDontSave;
    }

You will get this message, probably when saving scene: "Cleaning up leaked objects in scene since no game object, component or manager is referencing them. Mesh has been leaked # times." But it is harmless.

However, if you find a way to avoid that message, it would be nice to know how.


EDIT: Move the initialization code from OnEnable to Awake function, I don't get "leaked objects" message after that.