应用程序杀死了 c++ - 内存问题?
我用 C++ 编写了一个程序来执行蒙特卡洛。问题是,经过五次迭代(每次迭代都以不同的配置运行蒙特卡罗)后,该进程被终止。
一开始我认为这是一个内存问题,但在阅读了这篇关于内存管理的好文章(http://stackoverflow.com/questions/76796/memory-management-in-c)后,我的范围界定似乎是正确的。
我不使用大量内存,因为我的结果存储在一个相对较小的数组中,该数组在每次迭代时都会被重写。在一次迭代中,我没有使用比前一次更多的内存。
如果有的话,我找不到泄漏在哪里。我有很多函数调用要执行 计算,但是一旦我退出函数,我不需要销毁对象,对吧?
有什么建议吗?
编辑:该程序占用了我计算机的所有处理器能力,当它运行时我什至无法移动鼠标。
提前致谢。
编辑已解决:问题是我没有删除我使用的指针,因此每次迭代都不会释放内存,并且使用更多内存创建了一组全新的指针。非常感谢那些回答的人。
I wrote a program in c++ to perform montecarlo. The thing is that after five iterations (every iteration runs monte carlo with different configurations), the process is killed.
At the begining I thought it was a memory problem but after reading this nice post on memory management (http://stackoverflow.com/questions/76796/memory-management-in-c), my scoping seems to be correct.
I do not use a lot of memory since my results are stored in a relativelly small array which is rewritten ever iteration. In an iteration I am not using more memory than in the previous.
I cannot find, if there is any, where is the leak. I have a lot of function calls to perform
the calculations, but I do not need to destroy the objects once I am out of the function right?
Any tip?
EDIT: The program takes all the processor power of my computer, when it is running I cannot even move the mouse.
Thanks in advance.
EDIT SOLVED: The problem was that I was not deletening the pointers I used so every iteration the memory was not delocated and a whole new set of pointers was created using more memory. Thanks a lot to those that answered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您所在的平台,您可以使用 valgrind 或 vld 查找程序中的内存泄漏。
Depending on the platform you are on, you can use a tools like valgrind or vld to find memory leaks in your program.