RhinoApp().ActiveDoc()->ReplaceObject() uses lots of memory ?(C++/MFC/Rhino5)

I want to design an animation like below,but I find to use lots of memory so that PC crash.
I change my mesh by ReplaceObject().

for(int i =0 ; i < 600 ; i ++ )
{
    wait_time(); //1/30s
    RhinoApp().ActiveDoc()->ReplaceObject(....);
    RhinoApp().ActiveView()->Redraw();
}

I think Old data still is saved. Anybody know what happen ?

I think you would be much better of by using a DisplayConduit to do the animation for you. That way you can have one mesh, move it by incremental transform operations, and draw it.

If you replace the mesh each 1/30th of a second you get a huge undo stack (each replacement adds to the undo stack) that will eventually crash Rhino.

Doing animation by continuing to replace the object in the document very inefficient and a great way to fill up Rhino’s Undo stack, which is why you “use lots of memory.” As @menno has mentioned, you should considering dynamically drawing the animation using a display conduit. Here is an example to get you started.

https://github.com/mcneel/Rhino5Samples_CPP/tree/master/SampleAnimator

I got it. thanks ! :smile:

Any function can close Undo stack temporarily ?