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

岁酱吖の 提交于 2019-12-01 22:31:59
sharptooth

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:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!