O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting memory leaks

Let's take a simple program that has some memory leaks and explore how the Valgrind tool, with the help of Memcheck, can help us detect memory leaks. As Memcheck is the default tool used by Valgrind, it is not necessary to explicitly call out the Memcheck tool while issuing the Valgrind command:

valgrind application_debugged.exe --tool=memcheck

The following code implements a singly linked list:

#include <iostream>using namespace std;struct Node {  int data;  Node *next;};class List {private:  Node *pNewNode;  Node *pHead;  Node *pTail;  int __size;  void createNewNode( int );public:  List();  ~List();  int size();  void append ( int data );  void print( );};

As you may have observed, the preceding class declaration has methods ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required