Heap vs Stack

I'm writing a recursive function (for IDS/DFS algorithm), and using dynamic stack to save the nodes, which being initialized everytime I enter the function after some time I run out of memory and dont get an answer. Should I change my dynamic stack to regular stack, I mean from

 
  stack<node> *s = new stack<node>;

To
 
  stack<node> s;
If you create something with new you have to destroy it with delete when you are finished using it, otherwise you will have a memory leak.

Yes, you should avoid dynamic allocations, and only use it when you have to.
Thanks i forgot about the delete, but if the dynamic stack is empty, does it still take space on heap?
Yes.
deleting the allocated data is one thing. I also wonder if your recursion code runs too deep and broke the stack?
Topic archived. No new replies allowed.