Networking Reference
In-Depth Information
You may wonder what happens if your application is a multithreaded application.
Well, in that case, things get really complicated.
Detecting memory leaks
Memory management needs to be done carefully when an application is coded in
C or C++, since it is the developer's responsibility to manage the memory. For this
purpose, we are going to use a Linux-only tool called Valgrind . It can be used to
detect memory leaks or generate profiling data, among many other useful sanity
checks on the running code.
Firstly, the following section is a small tutorial on Valgrind where we will discuss
using Valgrind with ZeroMQ.
Introduction to Valgrind
You could compile your program with the -g parameter to include debugging
information. In that case, error messages will include exact line numbers. Using
-O1 can result in inaccurate messages, and using -O2 or -O3 definitely results in
inaccurate messages.
Consider the following example:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[]) {
char* a = malloc(4);
int b;
printf("b = %d\n", b);
return 0;
Let's compile with gcc -g -o test test.c . Now, it is time to run Valgrind to
check for memory leaks. Let's run the following command:
valgrind --leak-check=full --show-reachable=yes test
Search MirCeyron ::

Custom Search