0

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.

Altober
  • 956
  • 2
  • 14
  • 28
  • 4
    What error message(s) do you get when your process "is killed" ? – Paul R May 09 '11 at 10:00
  • 1
    Some code would also be useful. Try to isolate the code that you think is causing the problem. – dandan78 May 09 '11 at 10:01
  • Thanks for the reply Paul, it just says "killed" – Altober May 09 '11 at 10:02
  • 1
    "I do not need to destroy the objects once I am out of the function right? " Possibly wrong. It depends how you are creating them. –  May 09 '11 at 10:12
  • 1
    And in response to your edit, what OS is this on? The OS should not let your application take all the CPU. –  May 09 '11 at 10:16
  • 1
    If you're running on a Unix system, enable core dump with `ulimit -c unlimited`. You should get a core dump. – philant May 09 '11 at 10:19
  • The real question here is how did the app manage to kill c++? Has the committee been eradicated? – RedX May 09 '11 at 10:49
  • What if you run those iterations in different order? Is there something special about the fifth? – Beta May 09 '11 at 11:18
  • @unapersson you were right, thanks. Thanks all of you. – Altober May 09 '11 at 17:20
  • @Altober: If you have solved the problem yourself, post the solution as an answer and accept that. It is totally fine to accept your own answer. Also, to avoid such problems in the future, learn about [RAII](http://stackoverflow.com/questions/712639/). – Björn Pollex May 10 '11 at 06:26

1 Answers1

3

Depending on the platform you are on, you can use a tools like valgrind or vld to find memory leaks in your program.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283