This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use Valgrind (or a similar tool) to profile your application fro memory leaks

Hey everyone,

I'm developing an application using the PCA10001 board. After a while my app crashes. I think this is due to un-freed memory regions. When writing similar programs for linux I usually use Valgrind to profile my application and find memory leaks. Is there any way to do the same with this board? (or another, using JTAG)?

  • This isn't quite an answer, but a suggestion --- Perhaps you should consider avoiding dynamic memory if possible. If you aren't sure how to proceed, I'm sure members of this forum may have suggestions.

    Most embedded systems of this scale avoid the use of dynamic memory (due to a combination of factors, but the main three are: a) the limited memory available, b) the lack of a true OS/runtime to help manage the memory, and c) the run-time behavior of dynamic memory can be difficult to analyze, which makes it difficult to ensure the application will be suitably robust).

    If there is some reason you must use dynamic memory, an alternative to a memory profiler would be to add instrumentation code to every memory allocation/deallocation to try to spot problems. This isn't quite the same as Valgrind, which also tracks access, but it may provide information that would help you spot the problem. (Segger's Real-Time Terminal is a handy tool for this type of debugging. See Vebjørn's blog post devzone.nordicsemi.com/.../ )

Related