Most of the time we talk about static analysis tools, but dynamic analysis tools can be even more important when dealing with memory and threading issues. This is why instrumentation frameworks such as Valgrind are so important.
Starting with MonoTouch 5.4, developers can now use Valgrind to debug iOS-based applications. Valgrind 3.7.0 or later is recommended and it needs to be compiled with the flags “--enable-only32bit” and “--prefix=/usr/local”.
Valgrind comes with several tools out of the box:
- Memory error detector
- Two thread error detectors
- Cache and branch-prediction profiler
- Call-graph generating cache and branch-prediction profiler
- Heap profiler
Since this is a framework, developers occasionally create new Valgrind-based tools and variants.
Rolf Bjarne Kvinge warns that Valgrind can produce a lot of noise. The messages you need to watch for are “Invalid read of size X” and “Invalid write of size X”.