std::bad_alloc means that you requested more memory than is available.
You may have situations where the program does not leak, but memory is still running out:
vector<long> v; long n = 0; for(;;) { v.push_back(n++); }
ultimately exhaust all available memory on any machine that you have, but it does not leak - all memory is taken into account in the vector. Obviously, any container can be done in the same way, vector , list , map , does not really matter.
Valgrind only finds instances where you "refuse" to allocate, and not where you populate the system with currently available memory.
What LIKELY is doing is the slower form above - you save more and more in some kind of container. It can be that you cache, or that you do not delete when you consider that it was deleted.
Monitoring the amount of memory in the application is actually used in some kind of setup program ("top" on Linux / Unix, "task manager" on Windows) and in that it really grows. If so, then you need to figure out what is growing - for a large program that can be complicated (and some things MUST grow, others not ...)
Of course, it is also possible that you suddenly get a bad calculation, for example. request a negative number of elements in T* p = new T[elements]; will cause poor alloc, since elements are converted to unsigned, and negative unsigned numbers are HUGE.
If you can catch bad_alloc in the debugger, this kind of thing is usually pretty easy to spot because the large amount requested by new will be quite obvious.
Catching an exception in the debugger should generally help, although of course it is possible that you just allocate memory for a small line when it goes wrong, if you have something that is leaking, itβs not uncommon that this is what sets off when he goes wrong.
If you use the Unix flavor, you can also speed up the search for errors, set the amount of memory that the application can use for smaller sizes using ulimit -m size (in kilobytes) or ulimit -v size .