# Using Memcheck

Memcheck is the default tool used by Valgrind and the Valgrind plug-in for Eclipse. It allows you to detect memory-related problems such as memory leaks, use of uninitialized memory, and reads from/writes to inappropriate stack areas. For more information about Memcheck, refer to http://www.valgrind.org/docs/manual/mc-manual.html.

## Analyzing Memcheck Profile Results

Any memory management errors detected by Memcheck are displayed in the Valgrind view, which appears automatically after a profile run. Each displayed error can be expanded in the Valgrind view to display its stack trace.

In some cases, Memcheck can determine which section of the source code causes a reported error. Whenever this is the case, double-clicking on the stack trace of the reported error will open the related source file and place the insertion point on the line responsible for the error.

## Configuring a Memcheck Profile Run

To configure a Memcheck profile run, navigate to Profile As > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Memcheck Options .

The Memcheck Options tab allows you to configure the following Memcheck options:

- leak resolution sets how tolerant Memcheck should be in considering different stack traces to be the same. The default setting is "low", which means only the first two entries need to match. The "med" setting requires four entries to declare a match. The "high" setting requires all entries to declare match.

- freelist size (blocks) is identical to the Memcheck command-line option `--freelist-vol=`, which specifies the maximum total size (in bytes) of memory blocks to be marked "inaccessible" once they have been freed using `free` (as in C) or `delete` (as in C++). The default value for freelist size (blocks) is 10000000.

- minimum heap block alignment is identical to the Memcheck command-line option `--alignment=`, which specifies the minimum alignment/size of heap blocks. The default value for this option is 8.

- show reachable blocks configures whether or not Memcheck should report blocks it could not find a pointer to during leak detection. This is disabled by default (i.e. do not report blocks with undetermined pointers).

- undef value errors configures whether or not Memcheck should detect dangerous uses of undefined value errors. This is enabled by default.

- allow partial loads is identical to the Memcheck command-line option `--partial-loads-ok=`, which controls how Memcheck handles word-sized, word-aligned loads from addresses from which bytes are addressable and others are not. This is disabled by default (i.e. treat loads from partially invalid and completely invalid addresses as the same).

- gcc 2.96 workarounds is identical to the Memcheck command-line option `--workaround-gcc296-bugs`, which controls whether Memcheck should assume that small reads/writes below the stack pointer are due to bugs in gcc-2.96. This option is disabled by default (i.e. do not assume them to be reslting from gcc-2.96 bugs; report such reads/writes as errors).

Refer to http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles for information about Memcheck suppression files. For more information about each Memcheck option in the Valgrind plug-in for Eclipse, refer to `man valgrind`.