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
valgrind would not show a memory leak because you may well not have one that valgrind would find.
You can actually have memory leaks in garbage-collected languages like Java. Although the memory is cleaned up there, it does not mean a bad programmer cannot hold on indefinitely to data they no longer need (eg building up a hash-map indefinitely). The garbage collector cannot determine that the user does not really need that data anymore.
You may be doing something like that here but we would need to see more of your code.
By the way, if you have a collection that really does have masses of data you are often better off using std::deque rather than std::vector unless you really really need it all to be contiguous.
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: