Skip to main content

Sponsors

My Reversi is Memory Leak Free: Certified by Valgrind

When we write programs, we spend lots of time in managing memory. Improper memory management can lead to memory leak, therefore reserving memory that will never be used. Memory leak problems can be serious especially when an application needs to run for a long time. No matter how much memory you have, regular memory leaks can make you run out of memory eventually.

I run "valgrind" to check if my Reversi in C++ has memory leak problems.

$ time valgrind --tool=memcheck ./reversi
==4305== Memcheck, a memory error detector.
==4305== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==4305== Using LibVEX rev 1658, a library for dynamic binary translation.
==4305== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==4305== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==4305== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==4305== For more details, rerun with: -v
==4305==

(0,0): 9999990
7 1 1 1 1 1 1 1 1
6 1 1 0 0 0 0 1 1
5 1 1 1 0 1 1 0 1
4 1 1 0 1 1 0 0 1
3 1 1 0 0 1 1 0 1
2 1 0 1 0 0 1 0 1
1 1 1 0 0 0 0 1 1
0 1 1 1 1 1 1 1 1
  0 1 2 3 4 5 6 7

White: 44 Black: 20
Recursive evaluate: 53671516
Recursive end eval: 135214583
Evaluation: 44228633

==4305==
==4305== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
==4305== malloc/free: in use at exit: 0 bytes in 0 blocks.
==4305== malloc/free: 289,208,130 allocs, 289,208,130 frees, 6,940,995,120 bytes allocated.
==4305== For counts of detected errors, rerun with: -v
==4305== All heap blocks were freed -- no leaks are possible.

real    142m53.138s
user    139m9.606s
sys     0m37.606s

Hooray!!! But a 3min run becomes 2+hours run. Can it be faster?

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.