It sounds like you're getting ahead of yourself a bit. Vector allocation is already on the heap, but I don't think this is a heap/stack issue. It sounds like you want to do something unusual with lifetime management. If the 'node' is a POD then just use vector without pointers. The indirection you're introducing here is going to make iterating the vector very costly for no reason. It sounds like these objects have destructors though? I kind of want to know what's going on here, but even in that case you'd probably be better off doing manual mark and sweep if you need delayed destruction (why?).
The use case will be like:
Node* node1 = Node::Create();
// --> #Create is a static function where new Node is allocated to a memory pool, returning the pointer to the object.
// Everything about it will be handled by the pool.
Node* node2 = Node::Create();
node1.addChild(node2);
// ... addChild is:
void addChild(Node* node)
{
_children.push_back(node); // --> where _children should only point to those objects allocated (vector<Node*>).
}
In that case, if I make vector not a pointer to the Nodes, aren't I will be copying the values instead, which costs more? like _children.push_back(*node)?
And yes it has destructors. This node real case is an Entity in Entity-Component system. So yeah, entities are very active as part of the scene. As for why, I want them to get in (allocated) and out (deleted) off the game gracefully at the right timing, like when player pauses the game, changing scene, finishing a turn or combo input in turn based game, and of course when there's too much being already allocated and needs to be reused, etc. Small things that shouldn't let the screen stutters cause of it.