Flush ValueTree, Best Practices


What is the best practice to flush a ValueTree of all data?

Currently I am doing the following;

sessionTree = {};

…or is there a better way?


Depends whether you want it to be undoable or not, and whether you have other ValueTrees that refer to the same underlying object.

If you have multiple ValueTrees that point to the same thing, and you want them all to be affected by this, then you’d want to do this:

tree.removeAllChildren (undoManager);
tree.removeAllProperties (undoManager);

If you only have a single ValueTree or don’t care about listeners finding out that it has changed, then you can just point it to a new empty one with

tree = {};


In my case the ValueTree is the single master tree for the application. And, it does not necessarily need Undo capability. So, simply pointing to the empty tree will suffice.

I wanted to make sure I was not overlooking any edge cases, or worse, something obvious!

Thank you Jules. Thank you for JUCE. Thank you for your active help to all of us who learn and grow from this forum.