GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. Language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


A memory leak detection system for C++ Free Stuff

Abstract

This article presents a memory leak detection system called D.M.M. (Debug Memory Management) for finding memory leaks in C++ programs when the symbol NDEBUG is not set. This article has been superseded by a later article.

1. The system

Here is a class for implementing D.M.M.:

#ifndef ALREADY_INCLUDED_DMM_CLASS_HH
#define ALREADY_INCLUDED_DMM_CLASS_HH

class Dmm
{
public:
   virtual ~Dmm() { } /// ensures VTABLE* is the first element

public:
#ifdef DMM_ONLINE
   enum_debug_code debug_code;
#endif /* DMM_ONLINE */

Dmm(enum_debug_code debug_code)
   {
      (void)debug_code;
#ifdef DMM_ONLINE
      this->debug_code = debug_code;
#endif /* DMM_ONLINE */
   }

   ///
   /// NOTE: disables passing and returning by value
   ///
private:
   Dmm(const Dmm&);
   Dmm& operator = (const Dmm&);
};

#endif /* ALREADY_INCLUDED_DMM_CLASS_HH */

Click here to view the definition of the enum enum_debug_code. Every class that implements D.M.M. should inherit from the above class like so:

class Foo : public Dmm
{
public:
   Foo() : Dmm(DCODE_FOO)
   {
   }
};

Here is the header file for D.M.M.: dmm.hh Here is the footer file for D.M.M.: dmm.cc Here is a sample main function:

#include "../../2003/noio/io.hh"
#include "foo.hh"

int main()
{
#ifdef ALLEGRO_ONLINE
   allegro_init();
#endif /* ALLEGRO_ONLINE */

cout << "**** BEGIN t-dmm.exe\n";

Foo* f = new Foo();
   (void)f;

#ifdef DMM_ONLINE
   dmm_debug_print();
#endif /* DMM_ONLINE */

cout << "**** END   t-dmm.exe\n";

return EXIT_SUCCESS;
}
#ifdef ALLEGRO_ONLINE
END_OF_MAIN();
#endif /* ALLEGRO_ONLINE */

When you run this program, it will print a list of all unfreed memory for debugging purposes.



Back to Research Projects
This page has the following hit count:
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. Language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Sun Sep 25 16:11:46 NZDT 2016
Best viewed at 800x600 or above resolution.
© Copyright 1999-2016 Davin Pearson.
Please report any broken links to