My program fails with \'std::bad_alloc\' error message. The program is scalable, so I\'ve tested on a smaller version with valgrind and there are no memory leaks.
This
Run the program under debugger so that it stops once that exception is thrown and you can observe the call stack.
Three most probable problems are: