Index: src/Actions/Action.cpp
===================================================================
--- src/Actions/Action.cpp	(revision 5f612eea044e919bffc18a83cd7ddd35f981c765)
+++ src/Actions/Action.cpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -11,10 +11,11 @@
 #include "Actions/ActionRegistry.hpp"
 #include "Actions/ActionHistory.hpp"
+#include "Helpers/MemDebug.hpp"
 
 using namespace std;
 
 // An empty state to indicate success
-Action::state_ptr Action::success = Action::state_ptr(new ActionState());
-Action::state_ptr Action::failure = Action::state_ptr(new ActionState());
+Action::state_ptr Action::success = Action::state_ptr(Memory::ignore(new ActionState()));
+Action::state_ptr Action::failure = Action::state_ptr(Memory::ignore(new ActionState()));
 
 Action::Action(std::string _name,bool _doRegister) :
Index: src/Actions/ActionHistory.cpp
===================================================================
--- src/Actions/ActionHistory.cpp	(revision 5f612eea044e919bffc18a83cd7ddd35f981c765)
+++ src/Actions/ActionHistory.cpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -12,4 +12,5 @@
 #include "Patterns/Singleton_impl.hpp"
 #include "Helpers/Assert.hpp"
+#include "Helpers/MemDebug.hpp"
 
 using namespace std;
Index: src/Helpers/MemDebug.cpp
===================================================================
--- src/Helpers/MemDebug.cpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
+++ src/Helpers/MemDebug.cpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -0,0 +1,174 @@
+/*
+ * MemDebug.cpp
+ *
+ *  Created on: Apr 28, 2010
+ *      Author: crueger
+ */
+
+#include <iostream>
+#include <cstdlib>
+
+using namespace std;
+
+namespace Memory {
+  struct entry_t {
+    struct info_t {
+      char file[256];
+      int line;
+      size_t nbytes;
+      bool isUsed;
+      void *location;
+    } info;
+    bool isIgnored;
+    char checksum;
+    entry_t *prev;
+    entry_t *next;
+  };
+
+  entry_t *begin=0;
+  entry_t *end=0;
+
+  size_t state = 0;
+  size_t max = 0;
+
+  const int alignment = 8;
+
+  inline char calcChecksum(entry_t::info_t *info){
+    char *buffer = (char*)info;
+    char checksum =0;
+    for(size_t i=0;i<sizeof(entry_t::info_t);i++){
+      checksum+=buffer[i];
+    }
+    return checksum;
+  }
+
+  inline size_t doAlign(size_t nbytes){
+    int nonaligned = nbytes % alignment;
+    if(nonaligned) {
+     return(nbytes - nonaligned + alignment);
+    }
+    else{
+      return nbytes;
+    }
+  }
+
+  void getState(){
+    cout << "Maximum allocated Memory: " << max << " bytes" << endl;
+    cout << "Currently allocated Memory: " << state <<" bytes" << endl;
+
+    for(entry_t *pos=begin;pos;pos=pos->next){
+      cout << "\nChunk of " << pos->info.nbytes << " bytes" << " still available" << endl;
+      cout << "Chunk reserved at: " << pos->info.file << ":" << pos->info.line << endl;
+    }
+  }
+
+  void deleteEntry(entry_t *entry){
+    if(entry->isIgnored)
+      return;
+    if(entry->prev){
+      entry->prev->next = entry->next;
+    }
+    else{
+      begin = entry->next;
+    }
+
+    if(entry->next){
+      entry->next->prev = entry->prev;
+    }
+    else{
+      end = entry->prev;
+    }
+    entry->isIgnored = true;
+    Memory::state  -= entry->info.nbytes;
+  }
+
+  void _ignore(void *ptr){
+    static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
+    entry_t *entry = (Memory::entry_t*)((char*)ptr-entrySpace);
+    deleteEntry(entry);
+  }
+}
+
+void *operator new(size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
+
+  if(!nbytes) {
+    nbytes = 1;
+  }
+
+  static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
+
+  void *res;
+  if(!(res=malloc(entrySpace + nbytes))){
+    throw std::bad_alloc();
+  }
+
+  Memory::state += nbytes;
+  if(Memory::state>Memory::max){
+    Memory::max = Memory::state;
+  }
+
+  Memory::entry_t *entry = (Memory::entry_t*) res;
+  entry->info.nbytes = nbytes;
+  entry->info.isUsed = true;
+  strncpy(entry->info.file,file,256);
+  entry->info.file[255] = '\0';
+  entry->info.line=line;
+  entry->info.location = (char*)res + entrySpace;
+
+  entry->next=0;
+  entry->prev=Memory::end;
+  if(!Memory::begin){
+    Memory::begin=entry;
+  }
+  else {
+    Memory::end->next=entry;
+  }
+  Memory::end=entry;
+
+  entry->checksum = Memory::calcChecksum(&entry->info);
+  entry->isIgnored = false;
+
+  return entry->info.location;
+}
+
+void *operator new(size_t nbytes) throw(std::bad_alloc) {
+  return operator new(nbytes,"Unknown",0);
+}
+
+void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
+  return operator new(nbytes,file,line);
+}
+
+void *operator new[] (size_t nbytes) throw(std::bad_alloc) {
+  return operator new[] (nbytes,"Unknown",0);
+}
+
+void operator delete(void *ptr) throw() {
+  static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
+
+  Memory::entry_t *entry = (Memory::entry_t*)((char*)ptr-entrySpace);
+
+  if(Memory::calcChecksum(&entry->info)!=entry->checksum){
+    cout << "Possible memory corruption detected!" << endl;
+    cout << "Trying to recover allocation information..." << endl;
+    cout << "Memory was allocated at " << entry->info.file << ":" << entry->info.line << endl;
+    terminate();
+  }
+
+  entry->info.isUsed = false;
+  Memory::deleteEntry(entry);
+
+  free((char*)ptr-entrySpace);
+}
+
+void operator delete(void *ptr,const char*, int) throw() {
+  operator delete(ptr);
+}
+
+void operator delete[](void *ptr){
+  operator delete(ptr);
+}
+
+void operator delete[](void *ptr,const char*, int) throw(){
+  operator delete(ptr);
+}
Index: src/Helpers/MemDebug.hpp
===================================================================
--- src/Helpers/MemDebug.hpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
+++ src/Helpers/MemDebug.hpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -0,0 +1,31 @@
+/*
+ * MemDebug.hpp
+ *
+ *  Created on: Apr 28, 2010
+ *      Author: crueger
+ */
+
+#ifndef MEMDEBUG_HPP_
+#define MEMDEBUG_HPP_
+
+namespace Memory {
+  void getState();
+
+  void _ignore(void*);
+
+  template <typename T>
+  T *ignore(T* ptr){
+    _ignore((void*)ptr);
+    return ptr;
+  }
+}
+
+void *operator new   (size_t nbytes,const char* file, int line) throw(std::bad_alloc);
+void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc);
+void operator delete   (void *ptr,const char*, int) throw();
+void operator delete[] (void *ptr,const char*, int) throw();
+
+
+#define new new(__FILE__,__LINE__)
+
+#endif /* MEMDEBUG_HPP_ */
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 5f612eea044e919bffc18a83cd7ddd35f981c765)
+++ src/Makefile.am	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -86,4 +86,5 @@
 		 helpers.cpp \
 		 Helpers/Assert.cpp \
+		 Helpers/MemDebug.cpp \
 		 info.cpp \
 		 leastsquaremin.cpp \
Index: src/builder.cpp
===================================================================
--- src/builder.cpp	(revision 5f612eea044e919bffc18a83cd7ddd35f981c765)
+++ src/builder.cpp	(revision 632bc3e6a3aa135a6299c878abd3a7b67f1b355c)
@@ -81,4 +81,5 @@
 #include "version.h"
 #include "World.hpp"
+#include "Helpers/MemDebug.hpp"
 
 /********************************************* Subsubmenu routine ************************************/
@@ -2552,4 +2553,5 @@
   errorLogger::purgeInstance();
   ActionRegistry::purgeInstance();
+  ActionHistory::purgeInstance();
 }
 
@@ -2616,4 +2618,6 @@
 
   cleanUp(configuration);
+
+  Memory::getState();
   return (0);
 }
