Valgrind Alternative for Mountain Lion

Unfortunately, Valgrind does not support OS X 10.8 yet. After some Googling, I came across some forum posts where people were able to get it to compile and "almost" link. Does anyone know of any good alternatives to Valgrind for memory leak detection?


Solution 1:

Assuming you can be bothered, if you install MacPorts you will be able to install a functioning Valgrind (3.8.1 as for today) on your system. Unfortunately MacPorts will require you to install the whole XCode, not just the CL tools, so YMMV.

Solution 2:

While valgrind can be installed, the current state isn't very usable. In a simple program I got the following result;

==16016== 
==16016== HEAP SUMMARY:
==16016==     in use at exit: 63,264 bytes in 364 blocks
==16016==   total heap usage: 516 allocs, 152 frees, 67,154 bytes allocated
==16016== 
==16016== LEAK SUMMARY:
==16016==    definitely lost: 8,624 bytes in 14 blocks 
==16016==    indirectly lost: 1,168 bytes in 5 blocks
==16016==      possibly lost: 4,933 bytes in 68 blocks
==16016==    still reachable: 48,539 bytes in 277 blocks
==16016==         suppressed: 0 bytes in 0 blocks
==16016== Rerun with --leak-check=full to see details of leaked memory
==16016== 
==16016== For counts of detected and suppressed errors, rerun with: -v
==16016== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The same code will be fine with using valgrind on a linux.(compiled on their respective systems)

Solution 3:

The Instruments app (part of Xcode) is a very good way to look for leaks and run stress tests on the memory allocation of a running program.