C++ program dies with std::bad_alloc, BUT valgrind reports no memory leaks

前端 未结 2 817
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 01:50

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

2条回答
  •  甜味超标
    2021-01-21 02:09

    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:

    • heap fragmentation
    • too many objects created on heap (but still pointed to from the program)
    • a request for an unreasonably large block of memory

提交回复
热议问题