We need the simplest option on the reference counters for the following class tree:
struct AST { string val; vector<AST*> nest; void push(AST*); // nested tree elements virtual string dump(int depth=0); string pad(int); // dump tree }; struct Num:AST { Num(string); double val; string dump(int); }; struct Str:AST { Str(string); }; struct Op:AST { Op(string); }; struct Vector:AST { Vector(); } The problem is trying to implement a calculation on the tree:
AST glob("environment","global"); AST* AST::eval(AST*E=&glob) { for (it = nest.begin(), e=nest.end(); it!=e ; it++) (*it) = (*it)->eval(E); // вот здесь водопадная утечка памяти return this; } Not sure that shared_ptr is able to work with global data structures - the parser builds a global tree or graph in memory, then the handler runs on it (or somewhat in parallel, but this is in perspective), which this graph rebuilds, indexes, or builds a new part of the network bypassing existing related items. This is something from the field of implementation of semantic networks or Minsky frames , for a start - just an interpreter on trees with calculated attributes.